multithreading - Why does this sleeping barber solution not cause a deadlock? -
multithreading - Why does this sleeping barber solution not cause a deadlock? -
considering sleeping barber problem, have next solution have 2 status variables customer_available
, barber_available
in monitor:
get_haircut if num_free_chairs > 0 num_free_chairs := num_free_chairs - 1 customer_available.signal barber_available.wait do_haircut if num_free_chairs = n customer_available.wait barber_available.signal num_free_chairs := num_free_chairs + 1
now, assume first client goes in , calls customer_available_signal
, wakes barber up; assume barber thread starts , executes finish function , starts wait on customer_available
1 time again (assume thread calling do_haircut
method 1 time again , again). , context switches , client thread stucks on barber_available
status causing deadlock. so, solution seemed wrong me, same in several different sources.
is because methods in monitor atomic , client guaranteed phone call customer_available.signal
, barber_available.wait
sequentially before barber thread continues execution?
multithreading synchronization
Comments
Post a Comment