Delivered-To: lablgtk at yquem.inria.fr Date: Wed, 17 Sep 2008 08:41:13 +0900 (JST) Message-Id: <20080917.084113.241912566.garrigue at math.nagoya-u.ac.jp> To: matthieu.dubuget at gmail.com Subject: Re: [Lablgtk] GlGtk + Thread? From: Jacques Garrigue In-Reply-To: <48D017CE.6080007 at gmail.com> References: <48CD7229.6000503 at gmail.com> <20080916.080534.169572238.garrigue@math.nagoya-u.ac.jp> <48D017CE.6080007@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Cc: lablgtk at yquem.inria.fr Content-Type: Text/Plain; charset=iso-8859-1 Content-Length: 2437 From: Matthieu Dubuget Subject: Re: [Lablgtk] GlGtk + Thread? Date: Tue, 16 Sep 2008 22:32:14 +0200 > Jacques Garrigue a =E9crit : > = > > I'm not sure of the reason, but it probably means that GL doesn't l= ike > > to be called from different threads. Usually this problem of callin= g > > threads rather happens on windows, but apparently with GL this is t= he > > case for Unix too. The solution is to look at the explanations in > > GtkThread.mli, and issue all GL related calls through GtkThread.syn= c > > or GtkThread.async. > > Note that of course all calls directly from callbacks should be saf= e > > without wrappers, since they are called from the GUI thread > > themselves. > > = > > Tell us whether it solves your problem. > = > Thanks for your answer. Unfortunately, it did not work. > = > I tried to insert sync calls, but could not find where to put them: > = > The first GL related function is GlGtk.area. But it would seem strang= e > to call this function through GtkThread.sync? It is in the main threa= d, > isn't it? Actually, if you use "lablgtk2 -thread" an independent GUI thread is created at startup, and the main thread is not the GUI thread. This can be confusing, and for this reason I would suggest avoiding it in non-interactive use. As a matter of fact, if you use the following command line (just using GtkThread.main in place of Main.main), the GUI thread is the main thread, and everything works fine without any sync: lablgtk2 -I +threads unix.cma threads.cma gtkThread.cmo simple.ml But of course this is not very interesting as an experiment, since there is only one thread. After that you can try creating threads in callbacks, and see how it works. I also tried modifying simple.ml to work with lablgtk2 -thread, for a real experiment. You need to modify the last two lines of the main function: (* show must be called in the GUI thread *) GtkThread.async w#show (); (* Now wait for the GUI thread to quit *) Thread.join GtkThInit.thread Note that there is no need to create a main loop in this case, since there is already one running. Other calls like widget creation and callback connection usually don't require wrapping, particularly if the parent widget is not shown yet. Cheers, Jacques _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk