From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 100A2BCAE for ; Wed, 13 Jul 2005 16:10:54 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6DEArnY017655 for ; Wed, 13 Jul 2005 16:10:53 +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 QAA18713 for ; Wed, 13 Jul 2005 16:10:53 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6DEAoR6017643 for ; Wed, 13 Jul 2005 16:10:52 +0200 Received: from rosella (ppp13-169.lns2.syd3.internode.on.net [59.167.13.169]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id j6DEAJf6030172; Wed, 13 Jul 2005 23:40:39 +0930 (CST) Subject: Re: [Caml-list] Concurrency for services From: John Skaller To: Richard Jones Cc: caml-list@inria.fr In-Reply-To: <20050713085928.GA32362@furbychan.cocan.org> References: <20050713.004043.123299672.Christophe.Troestler@umh.ac.be> <1121229212.27378.23.camel@localhost.localdomain> <20050713085928.GA32362@furbychan.cocan.org> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-GVFc5Eukksgrs/9Kaxan" Date: Thu, 14 Jul 2005 00:10:19 +1000 Message-Id: <1121263819.6765.26.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 X-Miltered: at concorde with ID 42D520ED.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42D520EA.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 ocaml:01 threads:01 stack:01 malloc:01 malloc:01 heap:01 stack:01 inlining:01 mlton:01 eliminates:98 wrote:01 sourceforge:01 sourceforge:01 X-Attachments: type="application/pgp-signature" name="signature.asc" X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: --=-GVFc5Eukksgrs/9Kaxan Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Wed, 2005-07-13 at 09:59 +0100, Richard Jones wrote: > > Actually a version for Ocaml is possible although I > > haven't tried to create one yet -- Felix targets C++ > > but it should work for any language which supports > > classes with virtual functions and switches. >=20 > It should definitely be possible in OCaml. For anyone who wants to > see how this trick is done (in C using setcontext), also look at: > http://www.annexia.org/freeware/pthrlib Ah yes, but there is an important difference: this library supports C code by swapping machine stacks. This works, but it isn't capable of supporting large numbers of threads due to a lack of address space: each stack must reserve the maximum possible amount of memory it could use. If you use malloc, it is even worse, since malloc is required to allocate memory (not merely address space). This kind of library is actually a good argument for a 64 bit processor :) Felix uses a linked list of heap allocated stack frames to avoid this problem. Stackless Python works this way too I think. The cost is slow allocation, however that wouldn't apply to an Ocaml version. Also the whole program optimiser eliminates many calls by inlining, or by observing that there is no blocking operation in the control path, which allows the machine stack to be used instead. The C++ version also switches much faster than setjump/longjmp since only 'the usual' function call overhead is incurred, there's no need to save the whole CPU state. MLton uses linear stacks, but they're not machine stacks, and MLton's copying collector can grow and shrink them. There's another problem with the C stack swapping trick -- it only works with C. It may or may not work with C++, and it is very unlikely to work properly in a multi-language environment (eg: C and Ocaml together). BTW: I'm curious if g++ supports get/setcontext? --=20 John Skaller Download Felix: http://felix.sf.net --=-GVFc5Eukksgrs/9Kaxan Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBC1SDLw7vY25tjqN4RAgExAJ0TB3qoCL2oWOfXTvnXMm+aHv3UxgCdHQuk yOS4oh306zaCdIWGicOjVhw= =KjzH -----END PGP SIGNATURE----- --=-GVFc5Eukksgrs/9Kaxan--