2

一个简单的实验表明,每个线程一次只允许一个 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 清理?

4

1 回答 1

3

拜托——这一切刚刚在 rcpp-devel 邮件列表中讨论过,这里是整个(短)线程的链接。简而言之,它不是RInside 析构函数,而是 RAPI 本身,RInside 仅通过更易于使用的 C++ 包装提供。

A follow-up post has been sent to r-devel as well and in that thread Simon clearly states that because of a number of static globals in R itself, a fix is unlikely.

于 2012-09-03T13:26:02.547 回答