What's the alternative to busy waiting for all worker-threads to terminate?
Note 1: ETH::2. Semester::PProg
Deck: ETH::2. Semester::PProg
Note Type: Horvath Classic
GUID:
added
Note Type: Horvath Classic
GUID:
E%{Xlt1YG0
Previous
Note did not exist
New Note
Front
Back
What's the alternative to busy waiting for all worker-threads to terminate?
Using thread.join();
Performance trade-off:
Performance trade-off:
- Join (sleep, wakeup) typically incurs context switch overhead
- If worker threads are short-lived, busy waiting may perform better
- Later in the course: SpinLock
Field-by-field Comparison
| Field | Before | After |
|---|---|---|
| Front | What's the alternative to busy waiting for all worker-threads to terminate? | |
| Back | Using thread.join();<br><br>Performance trade-off:<br><ul><li>Join (sleep, wakeup) typically incurs context switch overhead</li><li>If worker threads are short-lived, busy waiting may perform better</li><li>Later in the course: SpinLock</li></ul> |
Note 2: ETH::2. Semester::PProg
Deck: ETH::2. Semester::PProg
Note Type: Horvath Cloze
GUID:
modified
Note Type: Horvath Cloze
GUID:
L;tWm+I&15
Before
Front
A bad interleaving is an interleaving that yields a problematic or otherwise undesirable computation. E.g. an incorrect result, a deadlock or non-deterministic output.
Back
A bad interleaving is an interleaving that yields a problematic or otherwise undesirable computation. E.g. an incorrect result, a deadlock or non-deterministic output.
After
Front
A bad interleaving is an interleaving that yields a problematic or otherwise undesirable computation.
Back
A bad interleaving is an interleaving that yields a problematic or otherwise undesirable computation.
E.g. an incorrect result, a deadlock or non-deterministic output.
Field-by-field Comparison
| Field | Before | After |
|---|---|---|
| Text | A {{c1::bad interleaving}} is an interleaving that yields |
A {{c1::bad interleaving}} is {{c2::an interleaving that yields a problematic or otherwise undesirable computation}}. |
| Extra | E.g. an incorrect result, a deadlock or non-deterministic output. |
Note 3: ETH::2. Semester::PProg
Deck: ETH::2. Semester::PProg
Note Type: Horvath Classic
GUID:
added
Note Type: Horvath Classic
GUID:
N=-BFf&KQi
Previous
Note did not exist
New Note
Front
What if a worker thread throws an exception?
Back
What if a worker thread throws an exception?
- Exception is (usually) shown on console
- Behaviour of thread.join() is unaffected
- \(\Rightarrow\) Main thread may not be aware of an exception inside a worker thread
Field-by-field Comparison
| Field | Before | After |
|---|---|---|
| Front | What if a worker thread throws an exception? | |
| Back | <ul><li>Exception is (usually) shown on console</li><li>Behaviour of thread.join() is unaffected</li><li>\(\Rightarrow\) Main thread may not be aware of an exception inside a worker thread</li></ul> |
Note 4: ETH::2. Semester::PProg
Deck: ETH::2. Semester::PProg
Note Type: Horvath Cloze
GUID:
modified
Note Type: Horvath Cloze
GUID:
OQfr*wOjfT
Before
Front
A thread starves if it can never enter a/any critical section.
Back
A thread starves if it can never enter a/any critical section.
After
Front
A thread starves if it can never enter a/any critical section.
Back
A thread starves if it can never enter a/any critical section.
Field-by-field Comparison
| Field | Before | After |
|---|---|---|
| Text | A thread {{c1::starves}} if it can |
A thread {{c1::starves}} if {{c2::it can never enter a/any critical section}}. |
Note 5: ETH::2. Semester::PProg
Deck: ETH::2. Semester::PProg
Note Type: Horvath Cloze
GUID:
added
Note Type: Horvath Cloze
GUID:
d%A(hxXDuk
Previous
Note did not exist
New Note
Front
The execution order is non-deterministic.
Back
The execution order is non-deterministic.
Field-by-field Comparison
| Field | Before | After |
|---|---|---|
| Text | The execution order is {{c1::non-deterministic}}. |
Note 6: ETH::2. Semester::PProg
Deck: ETH::2. Semester::PProg
Note Type: Horvath Cloze
GUID:
added
Note Type: Horvath Cloze
GUID:
mqvz~z;n#[
Previous
Note did not exist
New Note
Front
Threads can have a priority between 1 and 10:
Back
Threads can have a priority between 1 and 10:
JVM uses the priority of threads to select the one that uses the CPU at each moment.
t.setPriority(Thread.MAX_PRIORITY); // updates the thread's priority
t.setPriority(Thread.MAX_PRIORITY); // updates the thread's priority
Field-by-field Comparison
| Field | Before | After |
|---|---|---|
| Text | Threads can have a priority between {{c1::1}} and {{c1::10}}: | |
| Extra | JVM uses the priority of threads to select the one that uses the CPU at each moment.<br><br>t.setPriority(Thread.MAX_PRIORITY); // updates the thread's priority |
Note 7: ETH::2. Semester::PProg
Deck: ETH::2. Semester::PProg
Note Type: Horvath Cloze
GUID:
modified
Note Type: Horvath Cloze
GUID:
pO7Qm0Zc[}
Before
Front
Busy waiting occurs when a thread busily (actively) waits, e.g. by spinning in a loop, for a condition to become true.
Back
Busy waiting occurs when a thread busily (actively) waits, e.g. by spinning in a loop, for a condition to become true.
In the opposite scenario, the thread sleeps (i.e. is blocked) until the condition becomes true.
After
Front
Busy waiting occurs when a thread busily (actively) waits.
Back
Busy waiting occurs when a thread busily (actively) waits.
E.g. by spinning in a loop, for a condition to become true.
In the opposite scenario, the thread sleeps (i.e. is blocked) until the condition becomes true.
In the opposite scenario, the thread sleeps (i.e. is blocked) until the condition becomes true.
Field-by-field Comparison
| Field | Before | After |
|---|---|---|
| Text | {{c1::Busy waiting}} occurs when a thread |
{{c1::Busy waiting}} occurs when {{c2::a thread busily (actively) waits}}. |
| Extra | In the opposite scenario, the thread sleeps (i.e. is blocked) until the condition becomes true. | E.g. by spinning in a loop, for a condition to become true. <br><br>In the opposite scenario, the thread sleeps (i.e. is blocked) until the condition becomes true. |