[concurrency-interest] Is there something like an ordered or counting barrier
Fri, 31 Dec 2004 13:30:12 +0100
On Fri, 31 Dec 2004 16:21:10 +1000, David Holmes <email@example.com> wrote:
> > Of course you have to be careful with the construction of such a test
> > case, but - and this is what I am asking - what is the alternative?
> > How do others test their lock classes? You need multiple threads, but
> > then you need them to execute in a deterministic way to reproduce the
> > test scenarios you want to check.
> Like any class testing MT code ranges from basic black-box testing through
> to complex white-box testing. Simple black-box tests can be used that
> involve positioning threads at the right place eg. acquire a lock in one
> thread then assert the lock reports that thread as the owner; that a tryLock
> in another thread fails; that a Condition await/signal from another thread
> fails etc.
> Simple positioning can be done using synchronized sections, wait/notify or
> things like semaphores and barriers - it all depends what conditions you are
> trying to establish.
Well, this - simple positioning - is what I was trying to achieve with
the sequence barrier. I was using something like a CyclicBarrier or
pure synchronized blocks, but this let the code get soooo complicated.
Anyway, thanks for your suggestions for the sequence barrier (the
waitForTurn, signalNextTurn thing), I will incorporate it...