[R] problem with Rcpp and boost threadpool

Bert Gunter bgunter.4567 at gmail.com
Tue Dec 15 23:55:42 CET 2015


There is a Rcpp-devel mailing list that should be more suitable for this post.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Dec 15, 2015 at 11:44 AM, Ken Gosier via R-help
<r-help at r-project.org> wrote:
> I'm having a problem calling a local library through Rcpp with R Studio Server. It's a bit perplexing, since I have no issues when I call it from R at the command line.
>
> I've written an analytics library which uses boost's threadpool functionality for running multiple threads. I've stripped everything down to the bare essentials, the minimum code which will cause the problem -- this code just starts the threads in the threadpool, then exits them:
>
>
> #include <Rcpp.h>
>
> #include <boost/asio.hpp>
> #include <boost/bind.hpp>
> #include <boost/shared_ptr.hpp>
> #include <boost/thread.hpp>
> #include <boost/thread/thread.hpp>
>
> RcppExport SEXP test_thread()
> {
> BEGIN_RCPP
>     double retdbl = 10.4;
>
>     boost::shared_ptr<boost::asio::io_service::work> threadpool_work;
>     boost::asio::io_service threadpool_io_service;
>     boost::thread_group threadpool_threads;
>
>     threadpool_work.reset(  new
>     boost::asio::io_service::work(threadpool_io_service)  );
>     for (int i = 0; i < 6; ++i) {
>         threadpool_threads.create_thread(
>             boost::bind(&boost::asio::io_service::run, &threadpool_io_service));
>     }
>
>     threadpool_io_service.stop();
>     threadpool_work.reset();
>     threadpool_threads.join_all();
>
>     return(  Rcpp::wrap(retdbl)  );
> END_RCPP
> }
>
>
> When I run from command-line R, there's no problem, I get the double returned. However, when I run through R Studio Server, it either hangs endlessly, or it crashes when it gets to the create_thread statement.
>
> My version info is:
>
> R: R version 3.1.1 (2014-07-10) -- "Sock it to Me"
> R Studio: 0.99.489
> Linux: Linux Debian-Jessie 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux
> boost: 1.55
>
> Many thanks for any help!
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list