一个简单的实验表明,每个线程一次只允许一个 RInside 实例。
#include <RInside.h>
int main() {
RInside R1;
R1.parseEval("cat('Hello, R1\n')");
RInside R2;
R2.parseEval("cat('Hello, R2\n')");
return 0;
}
程序崩溃,输出如下:
Hello, R1
terminate called after throwing an instance of 'std::runtime_error'
what(): can only have one RInside instance
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
然而,另一个连续创建 RInside 实例的实验的结果还不是很清楚。
#include <RInside.h>
int main() {
RInside *R1 = new RInside();
R1->parseEval("cat('Hello, R1\n')");
delete R1;
RInside *R2 = new RInside();
R2->parseEval("cat('Hello, R2\n')");
delete R2;
return 0;
}
该程序在创建 R2 的那一刻嗡嗡作响。之前的输出如下所示:
Hello, R1
Lost warning messages
R1 析构函数调用是否不足以进行正确的 RInside 清理?