> > Thanks for the help. > > I took a stronger path and initialized to (fun _ -> assert false). > > It seems I have no more segfault (not sure yet as the segfault was no reproductible). In fact the segfault it still there, takes many run to observe it ... It is still in caml_callback_asm, meaning the global root pointing to the OCaml function has been corrupted. Note: I use caml_register_generational_root and caml_modify_generational_root to register and modify the pointer to the callback. I give my code doing the callback, following some example I found on the net, in case someone has a comment/hint. May be the order between Camlparam and acquire runtime is wrong ? This code reaquires the runtime lock, which is released only by the X event loop that performs the callback; This means that the same C thread release and acquire the global runtime lock. I have only two threads. -------------------------------------------------------------------- static void protect_callback(char *name, value f, value v1) { caml_acquire_runtime_system(); { CAMLparam2(f,v1); CAMLlocal1(res); res = caml_callback_exn(f, v1); if(Is_exception_result(res)) fprintf(stderr, "Egl.main_loop: " "WARNING: %s raised an exception\n", name) ; CAMLdrop; } caml_release_runtime_system(); } static void protect_callback2(char *name, value f, value v1, value v2) { caml_acquire_runtime_system(); { CAMLparam3(f,v1,v2); CAMLlocal1(res); res = caml_callback2_exn(f, v1, v2); if(Is_exception_result(res)) fprintf(stderr, "Egl.main_loop: " "WARNING: %s raised an exception\n", name) ; CAMLdrop; } caml_release_runtime_system(); } static void protect_callback3(char *name, value f, value v1, value v2, value v3) { caml_acquire_runtime_system(); { CAMLparam4(f,v1,v2,v3); CAMLlocal1(res); res = caml_callback3_exn(f, v1, v2, v3); if(Is_exception_result(res)) fprintf(stderr, "Egl.main_loop: " "WARNING: %s raised an exception\n", name) ; CAMLdrop; } caml_release_runtime_system(); } static void protect_callback4(char *name, value f, value v1, value v2, value v3, value v4) { caml_acquire_runtime_system(); { CAMLparam5(f,v1,v2,v3,v4); CAMLlocal1(res); CAMLlocalN(tmp,4); tmp[0] = v1; tmp[1]=v2; tmp[2]=v3; tmp[3]=v4 ; res = caml_callbackN_exn(f, 4, tmp); if(Is_exception_result(res)) fprintf(stderr, "Egl.main_loop: " "WARNING: %s raised an exception\n", name) ; CAMLdrop; } caml_release_runtime_system(); } > > Christophe > > > > > I have a multithreaded program, which segfault in callback_asm, while I > > think I respect all rules of c interfaces... Except maybe the above... > > > > > > There is an OPAM compiler switch "4.10.0+nnpcheck" that adds run-time checks > > for ill-formed values according to the no-naked-pointers rules.  Maybe you > > could use it to rule out this potential problem. > > > > Hope this helps, > > > > - Xavier Leroy > > > > > > > > Chevets, > > Christophe > > -- > > Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma > > brièveté. > >