Version française
Home     About     Download     Resources     Contact us    
Browse thread
threads & OCamlTK
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jerome Vouillon <Jerome.Vouillon@i...>
Subject: Re: threads & OCamlTK
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 */
     {
       CheckInit();

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

-- Jérôme