void Daemon::grouped( Channel channel ) { NOTE(); OutputMessage response( MessageType::Control ); if ( _state != State::FormingGroup ) { response.tag( Code::Refuse ); channel->send( response ); return; } Channel top, bottom; std::tie( top, bottom ) = Communicator::socketPair(); response.tag( Code::OK ); channel->send( response ); int pid = ::fork(); if ( pid == -1 ) throw brick::net::SystemException( "fork" ); if ( pid == 0 ) becomeChild( std::move( bottom ) ); else { _childPid = pid; becomeParent( std::move( top ) ); } }
void OptimisticTickSyncAlgo::timeStepStart(TIME currentTime) { #ifdef PROFILE if(!busywait) syncStart(); #endif if(currentTime < grantedTime){ if(this->isChild && comm!=NULL) comm->failTime=currentTime; return; } #if DEBUG_WITH_PROFILE CERR << "Start sync time step " << currentTime << " " << getCurTimeInMs() << endl; #elif DEBUG CERR << "Start sync time step " << currentTime << endl; #endif if(this->isChild){ //speculation worked so we kill the parent this->interface->waitforAll(); pid_t tempparId=this->parentPid; //try to send a kill signal comm->action=ACTION_SUCCESS; //detach from shm so parent can clean it. detachTimeShm(); becomeParent(); this->specFailTime=Infinity; #if DEBUG CERR << "I'm child my pid:" << this->mypid << "; killing parent " << tempparId << endl; #endif cout << "Success" << endl; //create new shared memory createTimeShm(); st->speculationSuceeded(currentTime); } else{ //cout << "I'm parent waiting for others!!" << endl; this->interface->waitforAll(); } }