[concurrency-interest] Queue with interrupt

Viktor Klang viktor.klang at gmail.com
Wed May 17 02:40:27 EDT 2017


If I interpret the email correctly, if the queue elements are of type `Job
| Wakeup`, then the second thread could offer a Wakeup if it wants to
interrupt the worker without having a Job.

On Wed, May 17, 2017 at 8:31 AM, David Holmes <davidcholmes at aapt.net.au>
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.
>
> David
>
> > -----Original Message-----
> > From: Concurrency-interest [mailto:concurrency-interest-
> bounces at cs.oswego.edu] On Behalf Of Jochen Theodorou
> > Sent: Wednesday, May 17, 2017 4:15 PM
> > To: concurrency-interest at cs.oswego.edu
> > Subject: [concurrency-interest] Queue with interrupt
> >
> > Hi all,
> >
> > yesterday I was looking for a certain behaviour, but was not finding one
> and I am wondering if I did overlook something.
> >
> > Situation:
> >
> > I have 1 Thread - lets call it worker, that needs to execute a series of
> tasks. If there are no tasks this thread has to wait for a maximum
> > of 5 seconds. After this time I have to send something like an update
> from this thread (has to be the same thread) to later continue on
> > waiting for tasks or handle the new ones. At this point I will not car
> if processing the tasks takes longer than 5 seconds. And now the
> > specialty: A second thread must be able to send an interrupt to the
> worker thread, which than has to stop waiting for new jobs and
> > send the update right away, to then get back to waiting for jobs. I
> cannot send the update from the interrupting thread.
> >
> > Now I was expecting to find something in a Queue implementation, but
> while I did find a way to wait for new elements, I did not find a
> > wait to interrupt that waiting. We solved this by using a BlockingQueue,
> plus some signaling, but it really does not feel right to me.
> >
> > Any idea how to do this better?
> >
> > bye Jochen
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at cs.oswego.edu
> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



-- 
Cheers,
√
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20170517/95113daa/attachment.html>


More information about the Concurrency-interest mailing list