From Kurt.Hornik at wu-wien.ac.at  Tue Sep 30 09:29:28 2008
From: Kurt.Hornik at wu-wien.ac.at (Kurt Hornik)
Date: Tue, 30 Sep 2008 09:29:28 +0200
Subject: [Rd] Rterm.exe, windows event loop running in multiple threads?
In-Reply-To: <509e0620809291706v733dff32s8772c48a3e9c42ee@mail.gmail.com>
References: <509e0620809180559k6c18a6e1he065daa5bd5a08d7@mail.gmail.com>
	<48D2578A.5040202@stats.uwo.ca>
	<509e0620809180638l19ded259w439bbcb8c2c1ba12@mail.gmail.com>
	<49633.192.54.49.174.1221746659.squirrel@webmail.ebi.ac.uk>
	<509e0620809291706v733dff32s8772c48a3e9c42ee@mail.gmail.com>
Message-ID: <18657.54616.392387.77519@fangorn.hornik.net>

>>>>> Michael Lawrence writes:

> On Thu, Sep 18, 2008 at 7:04 AM, Simon Anders <anders at ebi.ac.uk> wrote:
>> Hi Michael,
>> 
>> Michael Lawrence wrote:
>> >>> For processing events, RGtk2 has moved away from using the old tcl_do
>> hack
>> >>> and now synchronizes on the Windows event loop. In Rgui.exe this works
>> >>> fine
>> >>> (well mostly), but in Rterm.exe, users report the following warning
>> from
>> >>> GLib: "main loop already active in another thread". The most obvious
>> way
>> >>> this could occur is if the Windows event loop were iterating in
>> multiple
>> >>> threads. This does not seem to be the case from my casual inspection of
>> >>> the
>> >>> R source.
>> 
>> Following your advice, I have changed my HilbertCurveDisplay package from
>> the tcl_do hack to your threading technique.
>> 
>> IIRC, you start this second thread whose event handler gets called
>> periodically by a timer. It checks whether there are any pending Gtk
>> events, and if so, sends a message to the R main thread in order to cause
>> one GTK event loop iteration.
>> 
>> I have writen my gtkmm code the same way and got the same error message,
>> repeated many times. However, after I removed the check for pending events
>> from the handler of the timer event, the error message vanishes. It seems
>> that GTK does not like it if gtk_events_pending() is called from two
>> threads even if both threads refer to the same main loop. (Actually, it
>> does not mind, as the error is just a warning, and fucntionality ois not
>> disrupted. I guess that Rgui.exe gets the same warning but fails to
>> display it.)
>> 
>> Could this be the problem for you as well?
>> 
>> [Thinking a bout this again: Why, actually, do we need a second thread.
>> Could we not set up a Windows timer that dispatches a message to the main
>> thread's event handler peridoically to trigger a polling of the Gtk event
>> loop?]
>> 

> Thanks a lot for this tip. I have changed from using a thread to a
> timer, and uploaded it as RGtk2 2.12.7 to CRAN. If anyone wants to
> test, thanks!

Thanks, on CRAN now.

Best
-k



[Rd] Rterm.exe, windows event loop running in multiple threads?
Kurt Hornik