Re: threads & OCamlTK

From: Jerome Vouillon (
Date: Tue Mar 23 1999 - 16:07:29 MET

Date: Tue, 23 Mar 1999 16:07:29 +0100
From: Jerome Vouillon <>
To: Trevor Jim <>,
Subject: Re: threads & OCamlTK
In-Reply-To: <>; from Trevor Jim on Mon, Mar 22, 1999 at 01:39:10PM -0500

On Mon, Mar 22, 1999 at 01:39:10PM -0500, Trevor Jim wrote:
> I've been using camltk with threads for a while. I find it is faster
> to run Tk as its own process -- the thread scheduler doesn't seem to
> do a good job with Tk involved.

There is a mutex that prevents two Caml threads from running
simultaneously. I think what happens is that the Tk main loop
blocks while still holding the mutex.
You should try to release the mutex before entering this loop, and
acquire it again before each call to a Caml function. For instance,
in file cltkEvents.c:
    +extern void enter_blocking_section (void);
    +extern void leave_blocking_section (void);

     value camltk_tk_mainloop() /* ML */

       if (!signal_events) {
         /* Initialise signal handling */
         signal_events = 1;
         Tk_CreateTimerHandler(100, invoke_pending_caml_signals, NULL);
    + enter_blocking_section();
    + leave_blocking_section();
       return Val_unit;
and in file cltkCaml.c:
    callback2(*handler_code,Val_int(id),copy_string_list(argc - 2,&argv[2]));

-- Jérôme

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET