我在通過R Studio與R Studio Server調用本地庫時遇到問題。這有點令人困惑,因爲我在命令行從R調用它時沒有問題。RStudio在通過Rcpp調用boost :: threadpool時掛起
我寫過一個分析庫,它使用boost的threadpool功能來運行多個線程。我已經剝奪一切下降到最基本,最低的代碼,這將導致該問題 - 這個代碼只是開始的線程池的線程,然後退出他們:
#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:
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