[DGD] Continuations
Felix A. Croes
felix at dworkin.nl
Thu May 9 12:14:01 CEST 2019
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();
Regards,
Felix Croes
More information about the DGD
mailing list