[Rd] eventloop

Simon Urbanek Simon.Urbanek at math.uni-augsburg.de
Mon Apr 26 13:53:26 CEST 2004


On Apr 26, 2004, at 10:52 AM, l.bize at wanadoo.fr wrote:

> Hello.
> I'm writting a glx device and I've some performance problem with the 
> eventloop registration system. The device is not refresh when there's 
> no X event. That's problematic for animation and "smoothness" of 
> display.

> Should I use threads or fork the R process to get and independant
> way to refresh my device ? Or do you know another way to refresh it ?

I doubt you can use fork, since that way you'll end up having two 
independent R sessions (well, you could use IPC to communicate with an 
external device, but that's what xGD does w/o the need of forking an 
entire R - but I can tell you that it's fairly slow :P).

If you need a timed refresh (e.g. fixed frame-rate) then you can use 
threads for that (i.e. running your GD in a separate thread - but 
you'll have to store the entire display list locally). There are a few 
strings attached, though: you must make sure that any R calls (and 
accessing anything related to R) are made only in the initial R thread 
(this is often non-trivial). Furthermore the building process can get 
quite complicated, since every unix has different thread libraries, 
different flags etc. Finally you have to take utmost care that you 
don't interfere with the X loop driven by R (I'm not even sure if it 
can be done), unless you want to replace the regular X11 device 
entirely. Also I'm told that there are library-related issues when 
loading a threaded module into non-thread app.
But, still, you can give it a shot :) We use threads successfully with 
R (although in a bit different setting - running R as one thread of a 
multi-threaded application), but the above issues are really important 
and very nasty to debug if something goes wrong. There's also a very 
nice post about R and threads by Luke Tierney somewhere in the archives 
;).

I didn't check the EL API recently, but I thought you can wake up the 
loop via fd or generate a timer event... that should do I'd think ... 
Also you didn't tell us exactly which of the many versions of R GUI 
(raw stdin, readline, Tcl/Tk, Gtk, ...) you actually mean - since they 
use different event loops ...

OT: Did you have a look at 
http://wsopuppenkiste.wiso.uni-goettingen.de/~dadler/rgl/ ? Although 
its' not really a GD, it provides a kind of OpenGL device for R ...

Cheers,
Simon

---
Simon Urbanek
Department of computer oriented statistics and data analysis
University of Augsburg
Universitätsstr. 14
86135 Augsburg
Germany

Tel: +49-821-598-2236
Fax: +49-821-598-2200

Simon.Urbanek at Math.Uni-Augsburg.de
http://simon.urbanek.info



More information about the R-devel mailing list