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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-02-01 (14:31)
From: Ville-Pertti Keinonen <will@e...>
Subject: Re: [Caml-list] timer
On Tue, 2005-02-01 at 15:22 +0300, Anastasia Gornostaeva wrote:

> I have different FreeBSDs, 5.2rc2 and 5.3-release. 
> On 5.2rc2 using libc_r is by default but just now I use libmap.conf only for 
> ocaml-compiled programs to use pthreads. 

Does it work correctly for you when using libpthread on 5.2rc2 (it
might've still been called libkse)?

Does it work correctly with 5.3-release?  (I'd definitely expect it to.)

> I still dont believe it is only freebsd related problem if i use 
> freebsd 5.2rc2 for long time and with wide range of sowtware without 
> problems. For example, on my machine there is running Zope based on python 2.1,
> that is linked against libc_r. Well, i dont know if it uses signals ...

libc_r works most of the time, including signals, but OCaml makes a
particular misbehavior easy to trigger.

This is getting somewhat off-topic, but it still relates to getting
OCaml programs to work correctly, so...

Based on a quick look at the libc_r sources, it seems that what actually
happens is when entering a signal handler, the signal being delivered is
masked (as is sa_mask), and when leaving the handler, the original
signal mask is long as it hasn't been changed by the
signal handler.  OCaml always modifies the signal mask inside the

This seems like a misreading of the standard.  According to SUS3:

    When a signal is caught by a signal-catching function installed
    by sigaction(), a new signal mask is calculated and installed for
    the duration of the signal-catching function (or until a call to
    either sigprocmask() or sigsuspend() is made).


    If and when the user's signal handler returns normally, the
    original signal mask is restored.

Apparently the author of libc_r interpreted the "or until a call to
either sigprocmask() or sigsuspend() is made" to also cancel the
restoration of the original mask.

If you must use libc_r, the following modification might fix the problem
(disclaimer - I haven't tested it):

--- uthread_sig.c.orig  Wed Dec  3 08:54:40 2003
+++ uthread_sig.c       Tue Feb  1 15:52:53 2005
@@ -1112,12 +1112,14 @@
     struct pthread_signal_frame *psf)
        memcpy(&thread->ctx, &psf->ctx, sizeof(thread->ctx));
+#if 0
         * Only restore the signal mask if it hasn't been changed
         * by the application during invocation of the signal handler:
        if (thread->sigmask_seqno == psf->saved_state.psd_sigmask_seqno)
                thread->sigmask = psf->saved_state.psd_sigmask;
        thread->curframe = psf->saved_state.psd_curframe;
        thread->wakeup_time = psf->saved_state.psd_wakeup_time;
        thread->data = psf->saved_state.psd_wait_data;