in reply to Re: Boolean Thread::Semaphore ?
in thread Boolean Thread::Semaphore ?
This is a very bad idea.
A counting semaphore is fundamentally the wrong mechanism(*) for watermarking a queue; so futzing with the API of a counting semaphore to allow it to be used (badly) for this purpose is just all kinds of wrong.
(*)In brief, A counting semaphore is designed for controlling concurrent access to a resource that is limited but has multiple instantiations.
A queue, even a pre-limited queue, does not fit this criteria.
They are very different animals.
Those problems include:
Consumers and producers can become 'step-locked'.
The flow falls into a pattern of the consumer(s) all wasting many time-slices (and expensive context switches) waiting for the producer(s). Then alternately, the producer(s) all waste time-slices waiting for the consumer(s). The flow becomes lock-stepped wasting many context switches between each forward step.
The very purpose of queues is to alleviate this problem by acting as a flexible buffer removing the need for synchronisation.
See 940030 for a little more discussion.
|
|---|