caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile Starynkevitch <basile.starynkevitch@inria.fr>
To: erayo@cs.bilkent.edu.tr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Need advice for a mobile application server
Date: Thu, 20 Nov 2003 13:49:50 +0100	[thread overview]
Message-ID: <20031120124949.GA8495@bourg.inria.fr> (raw)
In-Reply-To: <200311201408.06069.exa@kablonet.com.tr>

On Thu, Nov 20, 2003 at 02:08:06PM +0200, Eray Ozkural wrote:

Eray> On Thursday 20 November 2003 11:27, Xavier Leroy wrote: [...]

Xavier>> Back to the original question: writing a multithreaded server in OCaml
Xavier>> is definitely feasible.  The only limitation to be aware of is that
Xavier>> OCaml threads do not offer parallelism, just concurrent execution.
Xavier>> What this means is that if there are several processors on your
Xavier>> machine, only one can execute OCaml code at any time, but other
Xavier>> threads (and therefore possibly other processors) can do I/O or C
Xavier>> computations in parallel.


Eray> I couldn't quite figure out why only one proc. can execute ocaml
Eray> code yet, but I can dig into the documentation :)

Mostly, because of the garbage collector. The Ocaml GC is very
efficient, and writing a generational [half-] copying *multi-threaded*
GC is quite difficult (as usual, the devil is in the
details). Actually, coding an efficient multithreaded GC with write
barriers using Posix threads is very tricky (if not impossible,
notably for synchronising minor GCs on every thread.) - for example
you'll probably need to access thread local storage on each
allocation, which (in portable C code) means calling
pthread_getspecific every time.


Regarding multi-threading in Ocaml, I think that it is much less
useful in Ocaml than say in Java or C. In my experience (on my
previous job) I started to code a multi-threaded application (the
POESIA monitor), and prefered to switch to a single-threaded design,
taking into advantage the functional abilities of Ocaml (i.e. mentally
replacing threads by sets of small correlated tasks, each represented
as functional values, ie closures, which means coding in a
continuation passing style). For instance the Unixqueue library (from
the Equeue software, used with Netclient) is single-threaded but very
useful to handle several "concurrent" communication channels
-e.g. HTTP or RSH connections.

Regards.
-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359
http://cristal.inria.fr/~starynke --- all opinions are only mine 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2003-11-20 12:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-19 18:03 Eray Ozkural
2003-11-20  5:34 ` skaller
2003-11-20  9:13   ` Richard Jones
2003-11-20  9:27     ` Xavier Leroy
2003-11-20 12:08       ` Eray Ozkural
2003-11-20 12:49         ` Basile Starynkevitch [this message]
     [not found]           ` <20031120161634.GA26689@redhat.com>
2003-11-21  8:48             ` Basile Starynkevitch
2003-11-21 17:06           ` skaller

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=20031120124949.GA8495@bourg.inria.fr \
    --to=basile.starynkevitch@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=erayo@cs.bilkent.edu.tr \
    /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;
as well as URLs for NNTP newsgroup(s).