在线程内创建RInside实例 我对编写一个能够运行R脚本的C++程序感兴趣。出于几个设计原因,我想创建一个RInside实例,执行一个脚本,获取结果,然后销毁该实例;都在一条线之内。我知道R不是多线程的,不能创建多个RInside实例。但是我可以在独立线程中创建单个实例吗?当我尝试执行此操作时,我的代码会编译,但在运行时出现以下错误: Error: C stack usage is too close to the limit Error: C stack usage is too close to the limit terminate called after throwing an instance of 'Rcpp::binding_not_found' what(): binding not found: '.AutoloadEnv' Aborted
以下是产生错误的代码:在线程内创建RInside实例 我对编写一个能够运行R脚本的C++程序感兴趣。出于几个设计原因,我想创建一个RInside实例,执行一个脚本,获取结果,然后销毁该实例;都在一条线之内。我知道R不是多线程的,不能创建多个RInside实例。但是我可以在独立线程中创建单个实例吗?当我尝试执行此操作时,我的代码会编译,但在运行时出现以下错误: Error: C stack usage is too close to the limit Error: C stack usage is too close to the limit terminate called after throwing an instance of 'Rcpp::binding_not_found' what(): binding not found: '.AutoloadEnv' Aborted,c++,r,pthreads,rinside,C++,R,Pthreads,Rinside,以下是产生错误的代码: #include <unistd.h> #include <stdio.h> #include <pthread.h> #include <RInside.h> void *thread_main(void *args){ RInside R(0,NULL); /* hope to execute an R script here */ printf("--printing from thread-
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include <RInside.h>
void *thread_main(void *args){
RInside R(0,NULL);
/* hope to execute an R script here */
printf("--printing from thread--\n");
return NULL;
}
int main(int argc, char *argv[]){
pthread_t tid;
if( pthread_create(&tid, NULL, thread_main, NULL) ){
printf("failed to create thread\n");
return -1;
}
sleep(1);
return 0;
}
#包括
#包括
#包括
#包括
空*线程\主(空*参数){
漂洗液R(0,空);
/*希望在这里执行R脚本*/
printf(“--从线程打印--\n”);
返回NULL;
}
int main(int argc,char*argv[]){
pthread_t tid;
if(pthread_create(&tid,NULL,thread_main,NULL)){
printf(“未能创建线程\n”);
返回-1;
}
睡眠(1);
返回0;
}
我尝试过按照编写R扩展时的建议设置R_CStackLimit=(uintpttr_t)-1
,但没有效果
我正在运行ubuntu,R版本2.15.2,RInside版本0.2.10
有可能做到这一点吗?还是我必须学习像Rserve这样的东西?
非常感谢你 R是单线程的,并且很可能会一直是单线程的。RInside会有一定的长度,以确保它被创建为一个单体;如果你颠覆了它,你会得到上面看到的错误。在同一个可执行文件中,您只获得一个RInside实例,因此每个线程一个实例将无法工作。正如你所经历的那样 请参阅我在源代码中提供的示例,了解在使用多线程前端(如Qt或用于webapps的Wt库)时如何处理单线程后端 从长远来看,我们或许能够做到Rserve所做的事情。代码贡献是受欢迎的,我可能没有时间来做这件事