Hi folks,

I've got a producer / consumer scenario and I've implemented a buffer class
that wraps a collection and exposes a method for consumers to retrieve
objects from the buffer.  It uses a semaphore to provide a wait handle for
the retrieval so that consumer threads will just block (with a timeout)
until there is something to consume.

This all works nicely, until I need to clear the buffer.  When I clear the
buffer I need to reset the semaphore's count back to 0, but Semaphore
doesn't seem to expose this functionality.  It looks like I need to close
the semaphore and create a new one, but if consumers are waiting on it they
get a ObjectDisposedException ('Safe handle has been closed').

Anyone handled this kind of scenario before?  I'm beginning to think I need
to detach the consumers, dispose and recreate the buffer and then attach the
consumers again...

Cheers,
Matt.

Reply via email to