在segment.destroy之后会发生什么?

时间:2013-06-18 07:28:46

标签: c++ linux boost interprocess

这是一个代码段,我想知道为什么[2]和[3]永远不会发出。

int main(int argc, char* argv[]){
const char *nSegmentName, *nInstanceName;
    using namespace boost::interprocess;    
    if(argc == 5){        
        mSegmentName = argv[1];
        mInstanceName = argv[2];
        mIdent = argv[3];
        mSender = argv[4];
        nSegmentName = ChStringChar(mSegmentName);
        nInstanceName = ChStringChar(mInstanceName);
        managed_shared_memory segment(open_only, nSegmentName);
        tpIF* instance = segment.find<tpIF>(nInstanceName).first;
        if (!instance) return 1;
        mDisplay = instance->GetDisplay();
        Run_EventLoop(instance);
        std::cout<<"\nSECTION END 0="<< mDisplay; // [1]
        std::cout.flush();
        segment.destroy<tpIF>(nInstanceName);
        std::cout<<"\nSECTION END 1="<< mDisplay; // [2]
        std::cout.flush();
    }
    std::cout<<"\nSECTION END 2"; // [3]
    std::cout.flush();
    return 0;
}

int Run_EventLoop(tpIF *nIns){
time_t timer, nWait = 1;
    std::cout<<"\nSECTION WAIT="<< nWait;
    std::cout.flush();
    while(nWait > 0){
        time(&timer);
        if(nIns->Test == 1){
            nWait = 0;
        }
    }
    std::cout<<"\nSECTION LOOP="<< mDisplay; // [4]
    std::cout.flush();
    return 0;
}
打印

[1]和[4],但不打印[2]和[3]。

我的问题:为什么不打印[2]和[3]?

0 个答案:

没有答案