Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Resumable exceptions in plain OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: oleg@p...
Subject: Re: [Caml-list] Resumable exceptions in plain OCaml

> Is your implementation thread-safe? My impression is it doesn't seems
> to be.

Interaction of dynamic binding and threading is quite an interesting
topic, which has been the subject of several papers (including ours,
which has been just accepted for ICFP). The implementation in used so-called shallow-binding -- this is the common
technique of implementing dynamic binding in Lisp and Scheme
systems. Alas, it doesn't well generalize to a multi-threading
environment. For multi-threading, a better approach is dealing with
the stack of handlers explicitly, keeping it in the thread-local
storage. Incidentally, this is the approach adopted in Scheme48, which
has a quite an advanced multi-threading system with user-defined
schedulers, channels and software transactional memory.

The best approach, in my opinion, is to `bind' exceptions handlers to
the stack (because the stack is the best `representation' of the
dynamic context). It is very simple (albeit requiring a small bit of C
code in the library of resumable exceptions) to get hold of OCaml's
own exception handlers. Also, we can use delimited continuations to
implement dynamic binding. That too solves all the problems. Alas,
currently delimited continuations are available only for byte code.

In any event, these performance improvement and generalizations will
not change the published interface of resumable exceptions.