Re: multiple threads consuming same list?



On Jun 13, 1:10 am, Steve Watt <steve.removet...@xxxxxxxx> wrote:
So, after 20 items, the producer will block on the condition variable
waiting for space in the buffer. 20 consumers will be scheduled to
run, but will most likely not have progressed beyond re-locking the
buffer mutex. So 30 consumers are still waiting for the condition to
be signalled with "not empty", and the producer is waiting on the same
condition, but for "not full" to be signalled. You're now in an area
where you must use cv_broadcast rather than cv_signal.

Ok. Now you have rung the bell. The point is that I thought it was a
monitor built from mutex and condition variable. It is not a monitor
since the semantics of the condition variable is not like what is
defined for the monitors.

In my interpretation the situation can occur because a signal on the
condition variable does not guarantee that the signalled thread re-
gains access to the shared data structure _before_ any other threads
that would just enter the `monitor' via the mutex. If the awakened
thread is delayed for some longer time after waking up from a
condition wait, other threads can gain access to the same shared data
in the meantime. This is the point the test should exercise, which is
not trivial how to do. Now I have some idea how to do it.

Thanks,
Szabolcs

.



Relevant Pages

  • Re: How can I make an efficient First-Come-First-Serve locking mechani
    ... "Threads that are waiting for ownership of a mutex are placed in a first in, ... > I have considered using a waitHandle, Monitor, or a C# lock statement ... Who will acquire the lock next? ...
    (microsoft.public.dotnet.general)
  • Re: Mutex deadlock problem (fixed line length)
    ... > an RTOS because my little OS did not do preemption. ... > make this work task A uses a mutex. ... > waiting on the mutex 4 B waits for another message 5 A ... Invokes the scheduler ...
    (comp.realtime)
  • Re: Block in synchronized mathod
    ... Where are those coming from in a Java ... malice, or possibly by design. ... but using coarse-grained monitors when you're waiting ... (remember you can use any old Object as a monitor). ...
    (comp.lang.java.help)
  • Re: [newbie] conditions: signal sent before waiter available?
    ... With a condition variable is a mutex associated. ... In the book, some examples demonstrate condition variables, waiting for signals, sending signals and awakening. ... So the usuale pattern to wait for a predicate is to lock the mutex that synchronize the access to the predicate and than check if that predicate is true. ...
    (comp.programming.threads)
  • Re: Block in synchronized mathod
    ... or possibly by design. ... but using coarse-grained monitors when you're waiting ... > lock under these different guards. ... > (remember you can use any old Object as a monitor). ...
    (comp.lang.java.help)