Please enable JavaScript.
Coggle requires JavaScript to display documents.
classical problem of synchronization (uses of semaphores (to protect a…
classical problem of synchronization
problem
readers writers
problem :
allow multiple readers to read at the same time . only 1 single writer can access the shared data at the same time
solutions
readers priority - no reader keep waiting unless writer has already abtained permission to access the database
writers' priority - if a writer is waiting to access database, no new readers can start reading
the solution above may cause
starvation
. semaphore solution to cure it :-
read-writer locks
dining philosophers
solution
no 2 neighbouring philosophers eat simultaneously, but has possibility of creating a deadlock
each philosophers invokes the operation
pickup()
&
putdown()
, no deadlock but starvation is possible
problem
- a large class or concurrency control problem; the need to allocate several resources among several processes in a
deadlock free
&
starvation free
manner
bounded buffer
aka producer-consumer problem
problem :
a finite buffer pool is used to exchange message btwn producer & consumer processes. bcause the buffer pool has max size
solution :
create 2 counting semaphores
full
&
empty
to keep track of the current number of full & empty buffers respectively
types of semaphores
empty
- to count no. of slots in the buffer tht are empty
full
- to count the no. of slots in buffer tht are full
mutex
- provide mutual exclusion for access to the buffer
uses of semaphores
to protect a relationship
empty and full as used in P/C prob
to support atomicity
pick up either both chopstick at same time or neither pick up just one
as
mutex
lock
to protect shared variables used in solving a prob such as readerCount in R/W prob above
to enforce an order on the interleaving of the statements in the processes to by synchronized
thread2 printing before thread1 in Order.java
to protect access to critical section
database in R/W problem
real world application
dining philosophers
printer
online cource scheduling
readers-writer
shared file on disk
database application
producer-Consumer
web server architecture
streaming audio or video