On Tue, May 18, 2010 at 9:56 PM, Matt Siebert <[email protected]> wrote:
> Thanks for getting me to lookup Monitors (Wait / Pulse) again.  I forgot
> about them ages ago.
>
> A Monitor is like a Mutex in that it guards a critical section so that it
> can only be executed by one thread at a time.
>
> I'm specifically after the counting functionality of a Semaphore so that
> consumer threads block when the buffer becomes empty, and are
> resumed when items are eventually added.
>
> See http://stackoverflow.com/questions/301160/what-are-the-differences-between-various-threading-synchronization-options-in-c

Ah okay, I understand now.


> It seems that the only way to achieve what I want would be to use
> a Monitor (or lock(object) { ... } construct) to guard access to the
> Semaphore but this negates the usefulness of the Semaphore.
>
> I think the best options are to swallow the exception and return null, or
> never allow the buffer to be cleared (i.e. force it to be reconstructed
> instead).

Seems like locking on the operation of clearing the buffer wouldn't be
the end of the world. But I don't quite know your situation, so I'm
sure you've got a better plan. It's kind of an interesting problem.

Sorry I've got no useful comments.


> Cheers.

-- 
silky

  http://www.programmingbranch.com/

Reply via email to