Slides 8 Flashcards
Define Race Condition
is a behavior where the output is dependent on the sequence or timing of other uncontrollable events (eg. context switching, scheduling on multiple CPUs)
What are some examples of race conditions?
modifying shared memory
• reading/writing to files
• modifying filesystems
• reading/writing to databases
If int x = counter;
x = x + 1;
counter = x; causes a race condition would replacing these 3 lines with counter ++; get rid of the race condition?
No because ++ is still 3 instructions in assembly and thus the modified data isn’t guaranteed to happen after each other instead of during
Define Critical section
part of the program that accesses the shared resource in a part of the program that access the shared resource in a way that could lead to races or other undefined/unpredictable/unwanted behaviour
What are the 4 requirements for a good, race-free solution?
- Mutual exclusion: No two processes/threads may be simultaneously inside their critical sections (CS)
- Progress: No process/threads running outside its CS may block other processes/threads.
- Bounded waiting: No process/thread should have to wait forever to enter its CS.
- Speed: No assumptions may be made about the speed or the number of CPUs.
What is a problem with asynchronous thread cancellation?
killed thread has no chance to “clean up”
• this can (likely) lead to leaving data in undefined state