[wg-parallel] About Lwt and Async

Jeremie Dimino jdimino at janestreet.com
Mon Apr 29 11:49:10 BST 2013


On Mon, Apr 29, 2013 at 11:38 AM, Mark Shinwell
<mshinwell at janestreet.com> wrote:
> I might be misunderstanding something about Lwt here, but as far as I
> see it, this latter point is quite important.  I believe one of the
> most important features of Async is the fact that you cannot be
> interrupted "between binds" by some arbitrary other job---whereas I
> do not think that is the case with the Lwt semantics (as far as I know,
> the equivalent to filling an ivar could cause something else to be
> run immediately; is that correct?).

You are right.  The equivalent of Ivar.fill is Lwt.wakeup (not wait,
my mistake) and it runs all thunk functions immediately.  However I
believe that people don't often rely on this behavior and changing it
to be the same as async wouldn't be a problem.  In fact there is
already a Lwt.wakeup_later function in lwt since Lwt.wakeup can be
problematic. It used to cause a stack overflow in Lwt_mutex for
instance.  That would require an addition to the signature of the Lwt
module to still be able to use it in an environment without a
scheduler (basically running all pending jobs).

> I think it's worth noting the [Monitor] construct of Async here,
> which encapsulates jobs with wrappers to direct any exceptions they
> might throw to appropriate places.

Indeed.  In lwt such exceptions are captured inside the lwt monad.


More information about the wg-parallel mailing list