From Simon.Urbanek at math.uni-augsburg.de  Mon Apr 26 13:53:26 2004
From: Simon.Urbanek at math.uni-augsburg.de (Simon Urbanek)
Date: Mon Apr 26 13:53:31 2004
Subject: [Rd] eventloop
In-Reply-To: <408CCDCC.8030602@wanadoo.fr>
References: <408CCDCC.8030602@wanadoo.fr>
Message-ID: <539C6666-9778-11D8-9EF7-000A957CEFBA@math.uni-augsburg.de>

On Apr 26, 2004, at 10:52 AM, l.bize@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@Math.Uni-Augsburg.de
http://simon.urbanek.info


[Rd] eventloop
Simon Urbanek