Process Syncronization
Process Syncronization
A significant problem with concurrent access to shared data is the possibility of race
conditions , deadlock , starvation etc
3. In the critical-section problem, Explain the following: (1) race condition (2) entry section
(3) critical section (4) exit section.
5. In the Semaphore solution to the Reader-Writer Problem, what is Semaphore mutex used
for?
In the Semaphore solution to the Reader-Writer Problem, the Semaphore mutex (short for
mutual exclusion) is used to control access to the critical section, ensuring that only one
thread (either a reader or a writer) can access the shared resource at a time. This helps in
preventing race conditions and ensuring that data integrity is maintained.
Busy waiting, also known as spinning, refers to a technique in which a process or thread
continuously checks for a condition to become true in a loop without yielding the processor
to other processes or threads.
8. In the Semaphore solution to the Dining-Philosophers Problem, what will happen if each
Philosopher picks up her left chopstick at the same time?
9. If each philosopher picks up her left chopstick at the same time in the
Semaphore solution to the Dining-Philosophers Problem, a deadlock may occur.
10. In the Semaphore solution, each philosopher needs to acquire both the left and
right chopsticks to be able to eat. If all philosophers simultaneously pick up their
left chopsticks and then attempt to pick up their right chopsticks, they will be
unable to proceed because they are waiting for the other philosopher to release
the chopstick they need.
12.The following program consists of three concurrent processes and three binary semaphores.
The semaphores initialize as S0=1 S1=0 S2=0. How many times will process p0 print “0”
Spinlocks:
• Description: Spinlocks are a form of busy waiting synchronization where a
thread continually checks a lock variable in a loop until it becomes available.
When a thread wants to enter a critical section of code protected by the lock, it
spins in a loop, continuously checking the lock's status. If the lock is held by
another thread, the spinning thread keeps checking until the lock is released.
Test-and-Set Instruction:
• Description: Test-and-set is a hardware-supported atomic instruction used for
synchronization. It atomically sets a memory location to a particular value and
returns its previous value. It is commonly used to implement spinlocks
efficiently.