caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Bigarrays and blocking_section..
@ 2010-05-25 16:25 Romain Beauxis
  2010-05-25 19:29 ` [Caml-list] " Dmitry Bely
  2010-05-26  6:00 ` Alain Frisch
  0 siblings, 2 replies; 6+ messages in thread
From: Romain Beauxis @ 2010-05-25 16:25 UTC (permalink / raw)
  To: caml-list

	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)
{
  CAMLparam1(_rgb);
  frame rgb;

  frame_of_value(_rgb,&rgb);
  caml_enter_blocking_section();
  rgb_blank(&rgb);
  caml_leave_blocking_section();

  CAMLreturn(Val_unit);
}

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

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

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 
stream/rgb_c.c:101
#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 ??


Romain


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-05-26  6:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-25 16:25 Bigarrays and blocking_section Romain Beauxis
2010-05-25 19:29 ` [Caml-list] " Dmitry Bely
2010-05-25 20:11   ` Romain Beauxis
2010-05-26  1:16     ` Goswin von Brederlow
2010-05-26  6:00 ` Alain Frisch
2010-05-26  6:47   ` Goswin von Brederlow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).