8 - Concurrent Programming Flashcards
What happens when a process calls for, and there are multiple threads?
Only the calling thread survives, other threads are not duplicated.
Is it safe to use fork in a program with multiple threads?
General advice: avoid using fork() in programs with multiple threads.
Some usages are safe, eg.:
• fork() is immediately followed by execve() to execute external
program, or
• fork() is executed before creating any threads
What is asynchronous thread cancellation?
One thread manually terminates the target thread
What is Deferred / Synchronous Thread Cancellation?
The controlling thread somehow indicates it wishes to cancel a thread
Target thread periodically checks whether it should terminate
• Checking done only at cancellation points at which it can be canceled safely.
What is a race condition?
A behavior where the output is dependent on
the sequence or timing of other uncontrollable events (eg. context switching, scheduling on multiple CPUs)
What is a Critical Section?
Part of the program that accesses the shared resource in a way that could lead to races or other
undefined/unpredictable/unwanted behavior
What is Mutual Exclusion?
Arranging tasks such that no two processes or threads will ever be in their critical sections at the same time.
What is a Shared Resource?
A resource available to more than one thread.
What are the requirements for a good race free solution?
1.Mutual exclusion: No two processes/threads may be simultaneously inside their critical sections (CS).
2.Progress: No process/threads running outside its CS may block other processes/threads.
3.Bounded waiting: No process/thread should have
to wait forever to enter its CS.
4.Speed: No assumptions may be made about the speed or the number of CPUs.