Rcpp Version 1.0.9
piWithInterrupts.cpp File Reference
#include <Rcpp.h>
#include <R_ext/Utils.h>
Include dependency graph for piWithInterrupts.cpp:

Go to the source code of this file.

Classes

class  interrupt_exception
 

Functions

static void check_interrupt_impl (void *)
 
bool check_interrupt ()
 
RcppExport SEXP PiLeibniz (SEXP n, SEXP frequency)
 

Function Documentation

◆ check_interrupt()

bool check_interrupt ( )
inline

Call this method to check for user interrupts. This is based on the results of a discussion on the R-devel mailing list, suggested by Simon Urbanek.

Attention
This method must not be called by any other thread than the master thread. If called from within an OpenMP parallel for loop, make sure to check for omp_get_thread_num()==0 before calling this method!
Returns
True, if a user interrupt has been detected.

Definition at line 64 of file piWithInterrupts.cpp.

References check_interrupt_impl().

Referenced by PiLeibniz().

Here is the call graph for this function:

◆ check_interrupt_impl()

static void check_interrupt_impl ( void *  )
inlinestatic

Do the actual check for an interrupt.

Attention
This method should never be called directly.
Parameters
[in]dummyDummy argument.

Definition at line 50 of file piWithInterrupts.cpp.

Referenced by check_interrupt().

◆ PiLeibniz()

RcppExport SEXP PiLeibniz ( SEXP  n,
SEXP  frequency 
)

Compute pi using the Leibniz formula (a very inefficient approach).

Parameters
[in]nNumber of summands
[in]frequencyCheck for interrupts after every frequency loop cycles.

Definition at line 75 of file piWithInterrupts.cpp.

References BEGIN_RCPP, check_interrupt(), END_RCPP, Rcpp::algorithm::min(), and Rcpp::wrap().

Here is the call graph for this function: