From anders at ebi.ac.uk  Thu Sep 18 16:04:19 2008
From: anders at ebi.ac.uk (Simon Anders)
Date: Thu, 18 Sep 2008 15:04:19 +0100 (BST)
Subject: [Rd] Rterm.exe, windows event loop running in multiple threads?
In-Reply-To: <509e0620809180638l19ded259w439bbcb8c2c1ba12@mail.gmail.com>
References: <509e0620809180559k6c18a6e1he065daa5bd5a08d7@mail.gmail.com>
	<48D2578A.5040202@stats.uwo.ca>
	<509e0620809180638l19ded259w439bbcb8c2c1ba12@mail.gmail.com>
Message-ID: <49633.192.54.49.174.1221746659.squirrel@webmail.ebi.ac.uk>

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

  Simon



+---
| Dr. Simon Anders, Dipl. Phys.
| European Bioinformatics Institute, Hinxton, Cambridgeshire, UK
| office phone +44-1223-494478, mobile phone +44-7505-841692
| preferred (permanent) e-mail: sanders at fs.tum.de



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