Please enable JavaScript.
Coggle requires JavaScript to display documents.
Synchronization (Semaphore (Implementation (Without Busy waiting…
Synchronization
Semaphore
-
-
-
-
-
Implementation
Must guarantee that no two processes can execute the wait() and signal() on the same semaphore at the same time
Implementation becomes the critical section problem where the wait and signal code are placed in the critical section
-
Solaris
-
-
-
Uses turnstiles to order the list of threads waiting to acquire either an adaptive mutex or reader-writer lock
Turnstiles are per-lock-holding-thread, not per-object
Implements a variety of locks to support multitasking, multithreading (including real-time threads), and multiprocessing
Priority-inheritance per-turnstile gives the running thread the highest of the priorities of the threads in its turnstile
Critical Section
When one process is in critical section, no other may be in its critical section
-
-
Solution
Mutual Exclusion - If a process is executing in its critical section, then no other processes can be executing in their critical sections
Progress - If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot 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 and before that request is granted
Approaches in OS
Preemptive
-
Preemption is the act of temporarily interrupting a task with the intention of resuming the task later
-
Non-preemptive
Runs until exits kernel mode, blocks, or voluntarily yields CPU
Peterson's Solution
Assume that the load and store machine-language instructions are atomic; that is, cannot be interrupted
-
-
-
-
Flag array is used to indicate if a process is ready to enter the critical section. flag[i] = true implies that process Pi is ready
Problems
Deadlock
Two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes
-
-
Classical problems
-
Bounded-Buffer Problem
-
n buffers, each can hold one item
-
-
-
-
-
Mutex Locks
-
-
Called a spinlock (lock which causes a thread trying to acquire it to simply wait in a loop while repeatedly checking if the lock is available)
Linux
-
On single-cpu system, spinlocks replaced by enabling and disabling kernel preemption
-
-
-