Mod 2: Synchronization Flashcards
What are saved in “the stack”?
(1) Reference to an object
(2) Value type data
What are saved in “the Heap”?
The objects data
What is requried in order for processes and threads to be able to work together?
That they can communicate with each other
How can two threads communicate with each other?
(1) Shared variables or objects
(2) Message passing through method calls
Why are both ways of communication between threads cumbersome and not easy to program?
(1) Thread runs only within the time they receive from CPU
(2) Threads may not complete an operation before CPU switches to another thread
Why does the application lack control over how threads run?
Because operating system has its own scheduler and algorithms to give threads CPU time to run
This also means that it entierly out of the application control when switches between threads takes place
Describe context-switching
(1) a thread is allocated a pre-defined time period to execute on the process
(2) when the time expires the thread’s context is saved until next run
(3) processor begins to execute next thread
What does interleave mean?
That an operation can consist of multiple step
What is an atomic operation?
The opposite of interleaving, meaning an operation happens without interleaving = either it happens completely or not at all. It cannot stop in the middle.
What does it mean in practic that an operation is atomic?
It will not have any side effects until the action is complete.
What do we need to ensure to achieve an atomic operation?
That only one thread has access to block of code at a time
What can we use to ensure atomic operations?
Critical Section protocols
How is critical sections protected?
By applying mutual exclusion etc.
What is “thread interference”?
Condition which occur when more than one thread, executing simultaneously, access same piece of data
What can happen when more than one thread access the same data?
The data may get corrupted or a thread may not get the desired output