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
Bigarrays and blocking_section..
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-05-25 (16:24)
From: Romain Beauxis <toots@r...>
Subject: Bigarrays and blocking_section..
	Hi all !

I am trying to understand some segfault that we observe and I have a question 
about the relationships between bigarrays in C and the Gc.

We have the following code:

static frame *frame_of_value(value v, frame *f)
  f->data = Caml_ba_data_val(Field(v,0));
  f->width = Int_val(Field(v,1));
  f->height = Int_val(Field(v,2));
  f->stride = Int_val(Field(v,3));

  return f;

CAMLprim value caml_rgb_blank(value _rgb)
  frame rgb;



My understanding is that after the line  "frame_of_value(_rgb,&rgb);", the C 
object rgb only contains ints and a pointer to a block of memory allocated by 

Hence, when releasing the global lock, the Gc should not mess with these 

However, we observe a segfault in this code:

Thread 5 (Thread 0x7fffe85ce910 (LWP 25190)):
#0  memset () at ../sysdeps/x86_64/memset.S:1023
#1  0x00000000006f18e2 in rgb_blank (rgb=0x7fffe85cda20) at stream/rgb_c.c:80
#2  0x00000000006f19fc in caml_rgb_blank (_rgb=140737119027336) at 
#3  0x0000000000543761 in camlBlank__fun_295 ()
Thread 2 (Thread 0x7fffe9dd1910 (LWP 25185)):
#0  0x00000000006f98dc in caml_do_local_roots ()
#1  0x00000000006ed325 in caml_thread_scan_roots ()
#2  0x00000000006f9fff in caml_oldify_local_roots ()
#3  0x00000000006fc480 in caml_empty_minor_heap ()
#4  0x00000000006fc5a9 in caml_minor_collection ()
#5  0x00000000006fd47d in caml_alloc_string ()
#6  0x00000000006ff9fb in caml_create_string ()
#7  0x00000000007094ec in caml_c_call ()

Apparently, the allocation of a string trigers a Gc minor collection which in 
turns messes with the frame and eventually segfault.

Can you help me understanding this ??