Message-ID: <4545E762.9010000 at laposte.net> Date: Mon, 30 Oct 2006 12:52:02 +0100 From: Matthieu Dubuget Reply-To: matthieu.dubuget at laposte.net MIME-Version: 1.0 To: lablgtk at math.nagoya-u.ac.jp Subject: Callbacks and threads Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Content-Length: 1270 Hello. I have a button b in a little application, which I want to trig function f (val f: unit -> unit) when clicked. f reads some value from hardware: it lasts 2~3 s. As a first try, I just did b#connect#clicked ~callback:f It works as expected. I know would like to: - modify IHM (change cursor, disable buttons...) with : val active : bool -> unit - call f - revert IHM modifications 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. I then tried: b#connect#clicked ~callback:( (fun () -> active false ; ignore (Thread.create (fun () -> f (); active true) ()) ) Unfortunately, this way, f is nether executed? Obviously, ~callback: (fun ()-> ignore (Thread.create (fun () -> lire_eeprom (); active true) ())) Does not work... What is the right thing to do (I mean except from stopping programming and drinking a good fresh beer)? Salutations Matt