[DGD] Continuations

nikoroleva natasha.i.koroleva at gmail.com
Thu May 9 16:12:56 CEST 2019


Felix A. Croes <felix at dworkin.nl> wrote:
>
> nikoroleva <natasha.i.koroleva at gmail.com> wrote:
>
> > I finally took a moment to experiment with this queue. Very cool feature!
>
> A few more remarks about the queue.
>
> The point of queue->dequeueCont() should be clear: it only runs when
> there is an element to retrieve from the queue.  But you may wonder what
> the purpose of queue->enqueueCont() is.  Why not call queue->enqueue(elem)
> directly?
>
> The answer is that the queue is optimized for Hydra's concurrency.
> Suppose that there are many LPC tasks which want to use this queue.  If
> all of them called queue->enqueue(elem), then each task would modify the
> queue object, and only one of those concurrently running tasks could
> complete successfully.
>
> The queue instead offers enqueueCont(elem) to create a continuation to
> enqueue the object.  Creating that continuation does not modify the
> queue, and can be done concurrently by an unlimited number of tasks.
> The actual enqueue tasks are run from the queue object, and are serialized
> so that they do not block eachother.  They are also guaranteed to succeed,
> because they don't affect any other object.
>
> The queue could perhaps be further improved in the following manner:
>
>     Continuation enqueueCont()
>     {
>         return new ChainedContinuation("enqueue");
>     }
>
> Then you could also do:
>
>     c = new Continuation("produceElement") >> queue->enqueueCont();
>     c->runNext();
>
These remarks call to mind some of the posts about continuations from
last autumn, and build on and reinforce those posts. Some things click
now that didn't before.


More information about the DGD mailing list