From: Sean O'Halpin Date: 2008-07-12T08:31:25+09:00 Subject: Re: Thread-safe priority queue? On Thu, Jul 10, 2008 at 8:03 PM, Joel VanderWerf wrote: > Joel VanderWerf wrote: >> >> Joel VanderWerf wrote: >>> >>> Looks like a race condition in that... >> >> Proposed fix, using a condition var... still needs some eyeballing and >> some tests: > > That was not quite right either (because cond.signal only wakes the waiter, > and doesn't schedule it). The following seems to complete without deadlocks > or starvation. > Thanks for taking the time to do this Joel. You can see why I was hoping it had already been done... ;) I resurrected the Queue code from an old copy of 1.8.4 I had lying around and went with that + your original version of the PriorityQueue. Still putting it through its paces. I'll give your new version a whirl too. @Roger - just putting a mutex around all the access methods isn't sufficient unfortunately (see Joel's code for evidence). I want the calling thread to block if there's nothing in the queue (like the standard lib Queue behaves). And once I start putting that machinery in, I might as well write the whole thing myself. I was hoping to avoid that (trying to be virtuous :) Regards, Sean