[concurrency-interest] Is there something like an ordered or counting barrier
Wed, 29 Dec 2004 10:57:35 +1000
> Because of that I made up a tiny class that does this for me
> and wanted to know if there are more elegant ways to do so and if this
> makes sense in the first place.
The class as depicted is relatively simple - though I would not have called
the method "count". Basically you are providing a "barrier" that lets
threads through in turn, where turn is indicated by the integer argument
presented to the barrier. The timeout aspect is curious because you will
proceed as if it were your turn on a timeout, even though it is not - that
doesn't seem good.
However, this barrier only controls the order in which threads pass the
barrier, not the order in which they perform their actual tasks. For
example, if a threads with arguments 1,2 and 3 are waiting when thread 0
comes along, then all four threads could pass the barrier before any thread
gets to do anything after the barrier. If the work itself were needed to be
performed "in turn" then I would expect a different approach:
So while the class does something, I'm not sure it does what you actually
want it to do.