Mindmap
Synchronisation

Inhalt der Mindmap
Synchronisation
Competition for Resources
- Critical Region
- Part of the program where the shared resources are accessed
- Aim to have no two processes in the critical region at the same time
- Part of the program where the shared resources are accessed
- Sometimes a process has to access shared resources leading to race conditions
- Race Condition
- Multiple threads/processes read and write a shared data item, and the final result is relative to timing of execution
- Race Condition
- Mutual Exclusion
- Requirement that when one process is in the critical region, no other processes can access those resources
- Mutual Exclusion Requirements
- 1. No two processes simultaneously in critical region
- 2. No assumptions about speeds/numbers in CPUs
- 3. No process running outside its critical region may block another process (deadlock)
- 4. No process must wait forever to enter critical region (starvation)
- Busy Waiting/Spinning
- Process repeatedly checks to see if a condition is true
- Consumes processor time
- Process repeatedly checks to see if a condition is true
- Mutual Exclusion Requirements
- Hardware Support
- Interrupt Disabling
- Disabling interrupts guarantees mutual exclusion
- Disadvantages
- Can be dangerous to allow processes to turn off interrupts
- Multiprocessing
- Can't ensure mutual exclusion
- Special Machine Instructions
- Atomic Action - Cannot be interrupted
- Either because it locks the memory bus
- or blocks interrupt mechanism
- Atomic Action - Cannot be interrupted
- Test and Set Instruction
- Advantage of Instructions: Applicable to any number of processes
- Exchange Instruction
- Interrupt Disabling
- Requirement that when one process is in the critical region, no other processes can access those resources
- Peterson's Solution
- 'Two Process Solution'
- LOAD and STORE are atomic (can't be interrupted)
- Two processes share two variables: int turn, boolean interested[2]
- turn
- Indicates whose turn it is to enter critical region
- interested
- Array is used to indicate if a process is ready to enter the critical section
- turn
- Two processes share two variables: int turn, boolean interested[2]
- LOAD and STORE are atomic (can't be interrupted)
- 'Two Process Solution'
- Critical Region
Semaphores
- Synchronisation tool which DOESN'T require busy waiting
- Semaphore S = integer variable for signaling
- Two atomic operations modify S: wait() and signal()
- wait()
- decrements semaphore value
- signal()
- increments semaphore value
- block() and wakeup() implementation - each semaphore has a waiting queue
- Waiting queue has value (type of integer) and pointer to next record
- block() - place process invoking operation in waiting queue
- wakeup() - remove a process in waiting queue and place in ready queue
- no busy waiting
- wait()
- Two atomic operations modify S: wait() and signal()
- 'Spinlock'
- Spins waiting for the lock
- Good solution is processes don't spend long in critical sections
- Semaphore S = integer variable for signaling
- Readers-Writers Problem
- Readers
- Only read the data set, don't perform updates
- Writers
- Can BOTH read and write
- Problem
- Only a single writer can access the shared data at the same time
- Shared data
- Data set
- Semaphore mutex
- Mutex = mutual exclusion
- Semaphore wrt
- readcount
- Shared data
- Only a single writer can access the shared data at the same time
- Dining-Philosophers Problem
- Deadlock-free solution
- 1. Allow AT MOST 4 philosophers sit at table
- 2. Allow a philosopher to pick up their chopsticks only if both are available
- 3. Use an asymmetric solution - Odd philsopher pciks up first left, then right chopstick, even vice versa
- Doesn't necessarily prevent starvation
- Deadlock-free solution
- Readers
- Synchronisation tool which DOESN'T require busy waiting
Bilder und Dateien der Mindmap
Informationen
- Beschreibung
- Computer Science Mindmap am Synchronisation, erstellt von Alex Bernini am 07/05/2019.
- Erstellt von
- Alex Bernini
- Aufrufe
- 0
- Bewertung


