Date: Thu, 30 Nov 2006 09:20:41 +0100 From: Maxence Guesdon To: Olivier Andrieu Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: strange behaviour of GMain.Main.main / GMain.Main.quit Message-ID: <20061130092041.1d52a40d at tintin.inria.fr> In-Reply-To: <17773.54865.833705.129071 at karryall.dnsalias.org> References: <20061129150731.3660ab96 at tintin.inria.fr> <17773.54865.833705.129071@karryall.dnsalias.org> Organization: INRIA Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Content-Length: 1929 On Wed, 29 Nov 2006 19:49:53 +0100 Olivier Andrieu wrote: > Salut Maxence, Salut Olivier, > Maxence Guesdon [Wednesday 29 November 2006] : > > > > Hello, > > > > I'm experiencing problems while using GMain.Main.main and > > GMain.Main.quit. Here is a program to reproduce the problem. It > > creates a window. When "Return" is pressed, the nb_waits counter in > > incrementend, then GMain.Main.main is called to wait for a > > GMain.Main.quit, then "pop!" is displayed (that is, when > > GMain.Main.main returns). When "Escape" is pressed, GMain.Main.quit is > > called nb_waits times. I thought that then all waiting "pop!" would be > > displayed one after the other but it works only when there is only one > > GMain.Main.main waiting. Is this a bug or a feature ? > > It's not a bug, that's just how the glib event loop API works. A > GMainLoop has a is_running boolean flag. g_main_loop_run basically > does a: > while (loop->is_running) process_events (loop); > and g_main_loop_quit simply sets loop->is_running to FALSE. > > To get this multiple level of loops, you'd need to create a new loop > object or something (but lablgtk doesn't wrap all the necessary > functions). Looking at the code in GtkMain, I see: let loops = ref [] let default_main () = let loop = (Main.create true) in loops := loop :: !loops; while Main.is_running loop do Main.iteration true done; if !loops <> [] then loops := List.tl !loops let main_func = ref default_main let main () = !main_func () let quit () = if !loops <> [] then Main.quit (List.hd !loops) So it seems that when I call GMain.Main.main () a new loop is created and it is destroyed when I call GMain.Main.quit (). Am I missnig something ? What happens to the code after the call to GMain.Main.main () in my example ? Maxence -- Maxence Guesdon http://yquem.inria.fr/~guesdon/ http://devel.inria.fr/rocq/