From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id B575BBB83 for ; Mon, 19 Jun 2006 23:41:58 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k5JLfvem021774 for ; Mon, 19 Jun 2006 23:41:57 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA22550 for ; Mon, 19 Jun 2006 23:41:57 +0200 (MET DST) Received: from selenite.metnet.navy.mil (selenite.metnet.navy.mil [192.16.167.32]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k5JLftM7032191 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 19 Jun 2006 23:41:56 +0200 Received: (qmail 7459 invoked by uid 107); 19 Jun 2006 21:41:47 -0000 Received: from vwmetnet.metnet.navy.mil (192.16.167.21) by selenite.metnet.navy.mil with SMTP; 19 Jun 2006 21:41:47 -0000 Received: from Adric.metnet.fnmoc.navy.mil ([10.100.105.102]) by vwmetnet.metnet.navy.mil (NAVGW 2.5.2.9) with SMTP id M2006061921531120808 ; Mon, 19 Jun 2006 21:53:11 GMT Received: by Adric.metnet.fnmoc.navy.mil (Postfix, from userid 760) id D3581AC97; Mon, 19 Jun 2006 14:40:12 -0700 (PDT) To: dmitry.bely@gmail.com Cc: caml-list@inria.fr In-Reply-To: <90823c940606180201h186824fbpe3b3d1976cc581fb@mail.gmail.com> Subject: Re: [Caml-list] Resumable exceptions in plain OCaml Reply-To: oleg@pobox.com Errors-To: oleg@okmij.org From: oleg@pobox.com Message-Id: <20060619214012.D3581AC97@Adric.metnet.fnmoc.navy.mil> Date: Mon, 19 Jun 2006 14:40:12 -0700 (PDT) X-Miltered: at nez-perce with ID 44971A25.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44971A23.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 oleg:01 thread-safe:01 threading:01 icfp:01 stack:01 bind':01 stack:01 ocaml's:01 delimited:01 delimited:01 byte:01 48,:98 caml-list:01 exception:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.0.3 > 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 resumable.ml 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.