1/14
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is the primary purpose of thread synchronization?
To allow concurrent accesses to variables while removing non-deterministic outcomes by enforcing the order of thread execution.
What outcomes are acceptable for concurrent reads and writes?
Multiple concurrent reads are acceptable, but multiple concurrent writes and one write with multiple reads are not acceptable due to non-deterministic outcomes.
What is a race condition?
A situation where the output of a concurrent program depends on the order of operations between threads.
What is a critical section?
A piece of code that accesses shared variables and must be executed by only one thread at a time.
What are the two methods associated with locks?
Lock::acquire() and Lock::release().
How does a lock function in relation to mutual exclusion?
A lock can either be BUSY or FREE; at most one thread holds the lock at any time.
Provide an example of how a race condition can manifest in a program involving two threads setting a variable x.
Thread 1 sets x=1; Thread 2 sets x=2; the final value of x can be either 1 or 2 depending on which thread executes first.
What is the result of the race condition example with two threads, Thread 1 and Thread 2, where Thread 1 reads y and Thread 2 updates y?
The final value of x can either be 13 or 25 depending on which thread executes first.
In the 'Too Much Milk' example, what correctness properties need to be addressed?
At most one person buys milk (safety) and someone buys milk if needed (liveness).
What can happen in 'Too Much Milk' Try #2 where both threads leave their own notes?
Starvation can occur, where one thread might wait indefinitely.
What does the entry section in a critical section involve?
Locking before entering the critical section and waiting if the lock is already taken.
What is a lock's state when it is first initialized?
The lock is initially in the FREE state.
What is the purpose of using locks in concurrent programming?
To ensure that shared data is accessed by one thread at a time, preventing data corruption.
What precautions should be taken when using locks?
Always acquire the lock before accessing shared data and release it after you're done.
Explain the dangers of not using locks when accessing shared data.
Accessing shared data without locks can lead to data corruption and unpredictable behavior.