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] Question about register_global_root
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Maas-Maarten Zeeman <maas@w...>
Subject: Re: [Caml-list] Question about register_global_root
Harry Chomsky wrote:

>Damien Doligez wrote:
>>On Sunday, June 1, 2003, at 12:50 PM, Maas-Maarten Zeeman wrote:
>>>The manual explicitly tells that register_global_root should be called
>>>before any valid value is stored in it for the first time, like
>>>Val_unit. See Rule 4 of Interfacing C with Objective Caml in the
>>I'm afraid Chris is right and the manual is wrong.
>>You must store a valid value before the first allocation that follows
>I think that both Chris and the manual are right.  The manual actually
>instructs the programmer to register a global root v "just before a valid
>value is stored in v for the first time".  Key word: "just".  In other
>words, as Damien says, no allocations are allowed between registration and
>storing a value.
>Apparently more than one reader of the manual has missed this detail.  Would
>it be clearer to say "immediately before" instead of "just before"?
Maybe it is better to be even more explicit.

Registration of a global variable v is achieved by calling 
register_global_root(&v), with v initialized to Val_unit, before 
allocating and storing a valid value in v for the first time.

On the other hand, some ocaml libraries (which are also examples) which 
use register_global_root, do not always follow this rule. i.e. 
install_signal_handler uses it like this:

  signal_handlers = alloc(NSIG, 0);

Is this also allowed?

All this also raises a question about the remove_global_root call, are 
there any special precautions I need to take just before or just after 
calling remove_global_root? Or can it be called at any time?


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