[wg-parallel] About Lwt and Async

Jeremie Dimino jdimino at janestreet.com
Mon Apr 29 11:54:19 BST 2013


On Mon, Apr 29, 2013 at 11:48 AM, Anil Madhavapeddy <anil at recoil.org> wrote:
> If I understand this right, Lwt exposes `wakeup` and `wakeup_later`,
> and the latter defers the wakeup until the scheduler is entered again.
> Therefore, `wakeup_later` is most similar to Async's model.

Almost.  The idea is that Lwt.wakeup_later pushes pending jobs to a
global queue and they are run at the end of the topmost
Lwt.wakeup/Lwt.wakeup_later, to avoid a stack overflow in some cases.

> I'm not sure if there are other ways in Lwt to interrupt a running
> thread, aside from Lwt_preemptive.  Is it sufficient to alias Lwt.wakeup
> to Lwt.wakeup_later?

Yes but that's not enough, we also need to remove the code running
pending jobs from Lwt.wakeup/wakeup_later, put it in its own exported
function, and call this function in the scheduler.  In scheduler-free
environment the latter may have to be called in some hook or at the
end of callbacks.


More information about the wg-parallel mailing list