2012-09-03 41 views
2

一個簡單的實驗顯示一次只允許每個線程有一個RInside實例。使用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. 

但是另一個實驗succesive 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清理?

回答