Date: Tue, 31 Oct 2006 08:45:39 +0900 (JST) Message-Id: <20061031.084539.74749515.garrigue at math.nagoya-u.ac.jp> To: matthieu.dubuget at laposte.net Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: Callbacks and threads From: Jacques Garrigue In-Reply-To: <4545E762.9010000 at laposte.net> References: <4545E762.9010000 at laposte.net> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: Text/Plain; charset=us-ascii Content-Length: 947 From: Matthieu Dubuget > I tried: > b#connect#clicked ~callback:( > fun () -> > active false; > f (); > active true; > ) > > f is called ok, except that: > - cursor change is not displayed during computation (seems like I have > to give control back to the main loop for this to happen?) > - if another button is clicked during the computation, the corresponding > callback is called after f has returned. This is the expected beahavior. > I then tried: > b#connect#clicked ~callback:( > (fun () -> > active false ; > ignore (Thread.create (fun () -> > f (); > active true) ()) > ) > > Unfortunately, this way, f is nether executed? This should work. However, you must link with gtkThread.cmo, otherwise the GTK main loop will not allow threads to be executed. (OCaml cannot switch threads during callbacks, so a thread-aware main loop is needed to allow thread-switching.) Jacques