Browse thread
Bigarrays and blocking_section..
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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)
{
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