04 - Synchronisation Flashcards
Mutual Exclusion
If a process is executing in its critical section, then no other processes can be executing in their critical sections
Critical Section
Segment of code where:
process may be changing common variables, updating table,
writing file, etc.
Critical-Section problem
Protocol that ensures safe access to shared resources by multiple threads or processes, preventing race conditions and ensuring data integrity during concurrent access to critical sections.
Progress
If no process is executing in its critical section and there are processes that want to enter their critical section, the selection of the process that will enter next can’t be postponed indefinitely
Bounded Waiting
A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section before that request is granted
Peterson’s Solution
Two Process Software Solution
Ensures mutual exclusion by providing a way for processes to take turns accessing a shared resource while preventing race conditions.
se of two shared variables, flags, and turn, along with careful synchronisation using atomic operations such as test-and-set or compare-and-swap.
Peterson variables
‘turn’
indicates whose turn it is
‘flag[i]’
indicates if process Pi is ready
Petersons Process Pi
‘flag[0] = true; turn =1;’
Enters critical section if Pj is not ready and turn is its own.
Petersons Process Pj
‘flag[1] = true; turn =0;’
Enters critical section if Pi is not ready and turn is its own.
Memory Barrier
Instruction ensuring changes in memory are visible to all processors
Memory Models
Guarantee memory behaviours in computer architectures
Strongly Ordered
Immediate visibility of memory modifications across processors
Weakly Ordered
Delayed visibility of memory modifications across processors
Memory Barrier Instruction
Ensures completion of loads and stores before subsequent operations
__sync_synchronize():
C function ensuring no memory operands move across the operation, backward or forward