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
[Caml-list] Threads question...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-20 (07:27)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] Threads question...
From: "Corey O'Connor" <>

> "The threads library is implemented by time-sharing on a single
> processor. It will not take advantage of multi-processor machines.
> Using this library will therefore never make programs run faster.
> However, many programs are easier to write when structured as several
> communicating processes."
> However, the documentation states that the native threads library is
> implemented using the system's native threading. (POSIX threads, in my
> case)
> Is the quote above still consistent with the native threads implementation?

Basically, yes.
With posix threads (or windows threads), every caml thread is mapped
to a posix thread, but there is a global mutex which any caml thread
must obtain before running. This makes sure for instance that memory
allocation and GC work properly.
So no more than one caml thread may run simultaneously, and you don't
gain from multiple CPUs.

However, contrary to vmthreads, this restriction only applies while
executing caml code. If you call some C function, you may choose to
first release the global lock (caml_enter_blocking_section), letting
other caml threads work while you are on the C side. Don't forget to
call lock again (caml_leave_blocking_section) when returning, or you
will crash very soon.

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: