dragooooon
May 7th, 2006, 09:32 PM
the context is producer/consumer
thread1
----------------------------------------------
p(empty)
mutexRW.lock()
produce(item)
mutexRW.unlock()
v(full)
-----------------------------------------------------
thread2
----------------------------------------------
p(full)
mutexRW.lock()
comsume(item)
mutexRW.unlock()
v(empty)
-----------------------------------------------------
I need to stop thread1 and thread2 sinultaneously in thread3.
How to avoid deadlock at p(empty) in thread1 for buffer is full or deadlock at p(full) in thread2 for buffer is empty ?
and I can't use a third mutex to achieve that because a third mutex would be unefficient for producer/consumer. so give me some clues to solve this problem please. thanks
thread1
----------------------------------------------
p(empty)
mutexRW.lock()
produce(item)
mutexRW.unlock()
v(full)
-----------------------------------------------------
thread2
----------------------------------------------
p(full)
mutexRW.lock()
comsume(item)
mutexRW.unlock()
v(empty)
-----------------------------------------------------
I need to stop thread1 and thread2 sinultaneously in thread3.
How to avoid deadlock at p(empty) in thread1 for buffer is full or deadlock at p(full) in thread2 for buffer is empty ?
and I can't use a third mutex to achieve that because a third mutex would be unefficient for producer/consumer. so give me some clues to solve this problem please. thanks