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

Kurt Hornik Kurt.Hornik at wu-wien.ac.at
Tue Sep 30 09:29:28 CEST 2008


>>>>> 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



More information about the R-devel mailing list