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
interaction between *_blocking_section and value
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-03-02 (22:32)
From: Samuel Mimram <samuel.mimram@e...>
Subject: interaction between *_blocking_section and value

I'd like to have some clarifications about the interaction between 
threads and the GC in C bindings.
As far as I understand the CAMLparam and CAMLlocal macros prevent values 
from being garbage-collected i.e.
1. being completely removed from memory,
2. being *moved*
during the whole scope of the C function (am I right?).
I have received a mail concerning one of my programs which was telling 
me that this is not true when in blocking sections, and that values can 
be moved by the GC. Is it the case? Consider the following code:

CAMLprim value caml_send(value data)
	send(0, String_val(data), string_length(data));

Is it safe or can the String_val(data) point to an invalid portion of 
memory because data have been move by the GC because of the 

Also, it would be nice if the *_blocking_section() could be explained in 
the documentation.