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] OCaml signal handlers (Sys.signal) and C code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-04-18 (13:01)
From: Damien Doligez <Damien.Doligez@i...>
Subject: Re: [Caml-list] OCaml signal handlers (Sys.signal) and C code
On Friday, April 18, 2003, at 10:41 AM, Stefano Zacchiroli wrote:

> Your "in any way" include also read only access (e.g. "Field" 
> invocation
> on a caml value allocated outside the blocking section), right?


> If this is the case I'm a bit concerned about performances. I have a
> piece of C code, invoked by OCaml, that access caml values inside a
> loop. To convert this code so that it can be interrupted by ocaml
> callbacks I have to enter blocking before each access and exit
> afterwards.

Actually, you have to leave blocking before the access and enter 

>  Is this entering/existing time consuming?

Unless you use threads, this is only one C function call, two tests,
and three assignments.  Not very time consuming, but you still don't
want to do it within an inner loop.

If this is too much overhead, here is what I would recommend.
Instead of calling leave_blocking_section and enter_blocking_section
around each heap access, you can treat the pair of calls:
    enter_blocking_section ();
    leave_blocking_section ();
as a way to poll for signals.  It will test for any pending signals
and call the handlers immediately.  If you call it once every 100 or
1000 loop executions, the overhead should be quite small.

-- Damien

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