From: John Skaller <skaller@users.sourceforge.net>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Concurrency for services
Date: Thu, 14 Jul 2005 00:10:19 +1000 [thread overview]
Message-ID: <1121263819.6765.26.camel@localhost.localdomain> (raw)
In-Reply-To: <20050713085928.GA32362@furbychan.cocan.org>
[-- Attachment #1: Type: text/plain, Size: 2015 bytes --]
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.
>
> 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?
--
John Skaller <skaller at users dot sourceforge dot net>
Download Felix: http://felix.sf.net
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2005-07-13 14:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-12 22:40 Christophe TROESTLER
2005-07-13 4:33 ` [Caml-list] " John Skaller
2005-07-13 8:59 ` Richard Jones
2005-07-13 14:10 ` John Skaller [this message]
2005-07-13 11:27 ` Gerd Stolpmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1121263819.6765.26.camel@localhost.localdomain \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=rich@annexia.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox