caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* vm threads
@ 2005-10-15  4:52 Ian Zimmerman
  2005-10-15  5:23 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Zimmerman @ 2005-10-15  4:52 UTC (permalink / raw)
  To: caml-list


Are Ocaml's VM threads preemptive?  That is, does the virtual machine 
actually have a timer and give a slice to each thread?  Or does a thread
run until it's blocked?

-- 
"It's not true or not."  A reality show producer (real quote)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] vm threads
  2005-10-15  4:52 vm threads Ian Zimmerman
@ 2005-10-15  5:23 ` Jacques Garrigue
  2005-10-15  5:52   ` Ian Zimmerman
  0 siblings, 1 reply; 4+ messages in thread
From: Jacques Garrigue @ 2005-10-15  5:23 UTC (permalink / raw)
  To: itz; +Cc: caml-list

> Are Ocaml's VM threads preemptive?  That is, does the virtual machine 
> actually have a timer and give a slice to each thread?  Or does a thread
> run until it's blocked?

The timer signal is used, so they are preemptive.
This is however only true for threads running ocaml code.
There is no way to switch thread during C calls, so that all
potentially blocking C calls should be manually converted to
non-blocking ones (this is already done for the standard library and
the Unix module.)
This can also create problems when somebody else needs the timer
signal (for instance the Graphics module.)

System threads are most costly (they use system resources), but they
simplify greatly working with C.

     Jacques Garrigue


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] vm threads
  2005-10-15  5:23 ` [Caml-list] " Jacques Garrigue
@ 2005-10-15  5:52   ` Ian Zimmerman
  2005-10-15  8:46     ` Jacques Garrigue
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Zimmerman @ 2005-10-15  5:52 UTC (permalink / raw)
  To: caml-list


Ian> Are Ocaml's VM threads preemptive?  That is, does the virtual
Ian> machine actually have a timer and give a slice to each thread?  Or
Ian> does a thread run until it's blocked?

Jacques> The timer signal is used, so they are preemptive.  This is
Jacques> however only true for threads running ocaml code.  There is no
Jacques> way to switch thread during C calls, so that all potentially
Jacques> blocking C calls should be manually converted to non-blocking
Jacques> ones (this is already done for the standard library and the
Jacques> Unix module.)  This can also create problems when somebody else
Jacques> needs the timer signal (for instance the Graphics module.)

The reason I asked was: when writing a library that uses C extension
code and a global data structure in the C code, can I just use system
thread primitives for synchronization (that would be pthreads since
I am only thinking about Unix type systems at least ATM) and not worry
about VM threads?

>From your post the answer seems to be yes.

-- 
"It's not true or not."  A reality show producer (real quote)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] vm threads
  2005-10-15  5:52   ` Ian Zimmerman
@ 2005-10-15  8:46     ` Jacques Garrigue
  0 siblings, 0 replies; 4+ messages in thread
From: Jacques Garrigue @ 2005-10-15  8:46 UTC (permalink / raw)
  To: itz; +Cc: caml-list

From: Ian Zimmerman <itz@buug.org>

> The reason I asked was: when writing a library that uses C extension
> code and a global data structure in the C code, can I just use system
> thread primitives for synchronization (that would be pthreads since
> I am only thinking about Unix type systems at least ATM) and not worry
> about VM threads?
> 
> From your post the answer seems to be yes.

That's even stronger than that: if you do not plan to run some pure C
threads concurently with ocaml, you usually don't need any
synchronization, either for system or VM threads.
With VM threads, you may only change thread when executing ocaml code,
so all your C code is single-threaded.
With system threads, you have to release the ocaml lock by calling
enter_blocking_section before any other ocaml thread may run.
If you don't want to be interrupted, just don't release it.
So you don't need to bother with synchronization as long as you don't
introduce concurrency intentionally on the C side. (But this might be
what you intend to do...)

Jacques Garrigue


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-10-15  8:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-15  4:52 vm threads Ian Zimmerman
2005-10-15  5:23 ` [Caml-list] " Jacques Garrigue
2005-10-15  5:52   ` Ian Zimmerman
2005-10-15  8:46     ` Jacques Garrigue

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).