【发布时间】:2015-12-15 19:28:39
【问题描述】:
我在使用 R Studio Server 通过 Rcpp 调用本地库时遇到问题。这有点令人困惑,因为我在命令行从 R 调用它时没有任何问题。
我编写了一个分析库,它使用 boost 的线程池功能来运行多个线程。我已经将所有内容都简化为最基本的内容,即会导致问题的最少代码——这段代码只是启动线程池中的线程,然后退出它们:
#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
}
当我从命令行 R 运行时,没有问题。我得到了双倍的回报。但是,当我通过 R Studio Server 运行时,它要么无休止地挂起,要么在到达 create_thread 语句时崩溃。
我的版本信息是:
- 回复:
R version 3.1.1 (2014-07-10) -- "Sock it to Me" - R 工作室:
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 - 升压:
1.55
【问题讨论】: