semaphore - In Producer/Consumer, why does switching the order of up(mutex) and up(fill) result in deadlock? -



semaphore - In Producer/Consumer, why does switching the order of up(mutex) and up(fill) result in deadlock? -

let's utilize code on wikipedia page example.

semaphore mutex = 1; semaphore fillcount = 0; semaphore emptycount = buffer_size; procedure producer() { while (true) { item = produceitem(); down(emptycount); down(mutex); putitemintobuffer(item); up(mutex); up(fillcount); } } procedure consumer() { while (true) { down(fillcount); down(mutex); item = removeitemfrombuffer(); up(mutex); up(emptycount); consumeitem(item); } }

why swapping position of up(mutex) , up(fillcount) in producer function guarantee deadlock? i'm trying come instance, can't seem find any.

deadlock semaphore producer-consumer

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -