Hi,
On Wed, May 31, 2000 at 02:35:14PM +0200, Jochen Hoenicke wrote:
>
> > I will change the parameter to the sleep method so it represents the top
> > TimerTask in the queue that you want to sleep on. Then sleep can check if
> > the top task has changed and return immediatly if it has changed and do
> > the real sleep otherwise (which should solve the race since sleep is
> > synchronized).
>
> I noticed later that there's a similar issue with the "stop" variable.
> You should move it to the queue class so that the sleep() method can
> check it, too.
Ack. You are right.
> Or maybe you put the whole sleep logic in Queue: You can add a
> synchronized method to Queue, that sleeps until the first task in the
> queue becomes ready, or the Timer was canceled. It returns the task
> and removes it from the queue, or returns null if the Timer was
> canceled.
Yes that might be best. I had hoped to make the priority queue a bit more
generic so that it could be used with other classes. But I will put all
the waiting logic in the queue for now since that makes things a lot simpler.
(those race conditions are awfully tricky.)
Thanks for your reviews,
Mark