[Rcpp-devel] Rcpp & Multithreading

Dirk Eddelbuettel edd at debian.org
Fri Apr 30 23:29:07 CEST 2010


Hi Jaiganesh,

Thanks for reposting here.

On 30 April 2010 at 16:50, Jaiganesh Balasubramanian wrote:
| Hi Folks,
| 
| I am creating a multi-threaded C++ application that initializes RInside in one
| of the child thread.
| 
| I would also like to access support interfaces like Rcpp::Environment in the
| remaining child threads, so that I could access any "R" function associated
| with the
| environment initialized.
| 
| When I run my program, I always get "C Stack limit too huge" errors.
| 
| I looked at the "Writing R Extensions" manual, and it pointed to initializing
| the R_CStackLimit variable to "-1", and
| that this initialization need to be made after the RInside constructor is
| called. I did that, but it still does not work.

Well, we already do that when RInside sets itself up:

    #ifdef CSTACK_DEFNS
    R_CStackLimit = (uintptr_t)-1;	// Don't do any stack checking, see R Exts, '8.1.5 Threading issues' 
    #endif

| Can you please let me know how do we accomplish this task?

I have not tried to do what you are doing here.  And maybe you can't.  R is
after all single-threaded.  So by hitting it from multiple threads might be 
pushing it too hard.

What I would do now is to create a sample program with two threads, then
initialize R in one and the query from the other. If that already tickles the
issue then you are out of luck, and R has to stay in one thread.  You may be
able to use inter-thread communication to 'request' data from the
R-containing thread by carefully brokering the requests.

-- 
  Regards, Dirk


More information about the Rcpp-devel mailing list