我有興趣編寫一個能夠運行R腳本的C++程序。出於幾個設計原因,我想創建一個RInside實例,執行腳本,獲取結果並銷燬實例;全部在一個線程內。我知道R不是多線程的,並且不能創建多個RInside實例。但是我可以在獨立線程中創建單個實例嗎?當我試圖做到這一點我的代碼編譯,但我會在運行時出現以下錯誤:在線程內創建一個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
這裏是產生錯誤代碼:
#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_CStackLimit = (uintptr_t)-1
爲在Writing R Extension中推薦,但無濟於事。
我在運行ubuntu,R版本2.15.2,RInside版本0.2.10。
可以做到這一點嗎?還是我必須學習Rserve? 非常感謝!