Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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?

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


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