From deepayan.sarkar at gmail.com  Thu May 31 22:13:54 2007
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Thu, 31 May 2007 13:13:54 -0700
Subject: [Rd] Calling R_PolledEvents from R_CheckUserInterrupt
Message-ID: <eb555e660705311313r75fce3acm4bf7adbdbbee114e@mail.gmail.com>

On 5/5/07, Luke Tierney <luke at stat.uiowa.edu> wrote:

[...]

> However, R_PolledEvents is only called from a limited set of places
> now (including the socket reading code to keep things responsive
> during blocking reads).  But it is not called from the interupt
> checking code, which means if a user does something equivalent to
>
>     while (TRUE) {}
>
> there is not point where events get looked at to see a user interrupt
> action. The current definition of R_CheckUserInterrupt is
>
> void R_CheckUserInterrupt(void)
> {
>      R_CheckStack();
>      /* This is the point where GUI systems need to do enough event
>         processing to determine whether there is a user interrupt event
>         pending.  Need to be careful not to do too much event
>         processing though: if event handlers written in R are allowed
>         to run at this point then we end up with concurrent R
>         evaluations and that can cause problems until we have proper
>         concurrency support. LT */
> #if  ( defined(HAVE_AQUA) || defined(Win32) )
>      R_ProcessEvents();
> #else
>      if (R_interrupts_pending)
>          onintr();
> #endif /* Win32 */
> }
>
> So only on Windows or Mac do we do event processing.  We could add a
> R_PolledEvents() call in the #else bit to support this, though the
> cautions in the comment do need to be kept in mind.

I have been using the following patch to src/main/errors.c for a while
without any obvious ill effects. Could we add this to r-devel (with
necessary changes for Windows, if any)?

-Deepayan

Index: errors.c
===================================================================
--- errors.c    (revision 41764)
+++ errors.c    (working copy)
@@ -39,6 +39,8 @@
 #include <R_ext/GraphicsEngine.h> /* for GEonExit */
 #include <Rmath.h> /* for imax2 */

+#include <R_ext/eventloop.h>
+
 #ifndef min
 #define min(a, b) (a<b?a:b)
 #endif
@@ -117,6 +119,8 @@
 #if  ( defined(HAVE_AQUA) || defined(Win32) )
     R_ProcessEvents();
 #else
+    R_PolledEvents();
     if (R_interrupts_pending)
        onintr();
 #endif /* Win32 */



[Rd] Calling R_PolledEvents from R_CheckUserInterrupt
Deepayan Sarkar