[R] memory allocation and interrupts

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Jun 12 10:47:17 CEST 2004


Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:

> On Fri, 11 Jun 2004, Vadim Ogranovich wrote:
> 
> > A recent discussion on the list about tryCatch and signals made me think
> > about memory allocation and signals in C extension modules. What happens
> > to the memory allocated by R_alloc and Calloc if the user pressed Ctr-C
> > during the call? R-ext doesn't seem to discuss this. I'd guess that
> > R_alloc is interrupt-safe while Calloc is not, but I am not sure. In any
> > case a paragraph in R-ext on signals would be helpful.
> 
> Easy: such code is not interruptible by Ctrl-C (sic).  And that *is* in
> R_exts.* (sic), even with an entry `interrupts' in its index!

The programmer might reenable interrupts though. This is not something
that we have a precedence (nor a policy) for, but it has crossed my
mind a couple of times. 

In some cases it should be possible to wrap time-consuming C code in a
setjmp/longjmp construct. It's not possible to do it generally because
all hell breaks loose if the C code calls back into R, but not all C
code does that. 

Of course it is critically important that the code resets the
interrupt handling to a sane state when it is done, so it would be
nice if we could abstract a reasonably safe construction into a
RUN_INTERRUPTIBLE() macro.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list