[concurrency-interest] Queue with interrupt

David Holmes davidcholmes at aapt.net.au
Wed May 17 05:29:33 EDT 2017


> -----Original Message-----
> From: Jochen Theodorou [mailto:blackdrag at gmx.org]
> Sent: Wednesday, May 17, 2017 7:26 PM
> To: dholmes at ieee.org; concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] Queue with interrupt
> 
> 
> 
> On 17.05.2017 08:31, David Holmes wrote:
> > Hi Jochen,
> >
> > How are you "waiting for tasks"? As you note a Queue has no notion of
> > blocking on empty. Using a BlockingQueue you can either interrupt the
> > worker thread or send a sentinel task that simply indicates "do the
> > other processing now". Of course I can't tell you know whether the
> > worker is waiting or working - you can't arbitrarily "interrupt" the
> > execution of a task.
> >
> 
> I think maybe it is better to show some code...
> See
> https://github.com/canoo/dolphin-platform/blob/master/platform/dolphin-platform-
> server/src/main/java/com/canoo/dolphin/server/context/DolphinContextTaskQueue.java
> 
> addTasks and interrupt are called from a different thread than executeTasks. executeTasks is responsible for one iteration of task
> executions, not a continuously blocking worker.
> 
> I do not want to interrupt task execution of course, only the waiting.
> 
> So your suggestion is to add a sentinel task... I guess that works, as long as I can add the task before already existing tasks, that may be
> still in the queue, so that it can interrupt between task executions ( not during of course)

If there are tasks in the queue then the worker is not waiting for new tasks to do - so you've changed your requirements. You would need a deque to allow sentinel tasks to be forced to the head of the queue.

David

 
> bye Jochen



More information about the Concurrency-interest mailing list