On Thu, 20 Mar 2014 00:21:36 +0100 Gerd Stolpmann wrote: > OCaml printing isn't printf in C - it calls directly write() and is > always possible. OCaml signal handlers aren't signal handlers from the C > viewpoint: When the signal is caught, a flag in the OCaml runtime is > set, and this flag is regularly checked by the running code. (I.e. what > you suggest is already done in the runtime.) > > So, I'd say this is a bug in the OCaml runtime. The bug goes away when > you print to a different channel from the signal handler, so it looks > like channels and signal handlers have some unwanted effect on each > other. stdlib channels are protected with non-recursive mutex, so the deadlock on re-entrant invocation is guaranteed. AFAICS runtime system tries to execute signal immediately (see signal_handle in asmrun/signals_asm.c) and if that is not possible - records signal for later execution. Anyway doing complex stuff in signal handler is a bad idea, because even with delayed processing (when things are safe from the libc point of view) the points of invocation of OCaml signal handler are scattered all around the program (allocation sites) and any OCaml resource that doesn't support reentrant usage will break the program. --