actor::actor(ActorStartRoutine routine) : parent_pipe_(nullptr), child_pipe_(nullptr), stopped_(false) { std::string pipe_endpoint; parent_pipe_ = new socket(actor_pipe_ctx_, socket_type::pair); pipe_endpoint = bind_parent(); child_pipe_ = new socket(actor_pipe_ctx_, socket_type::pair); child_pipe_->connect(pipe_endpoint); std::thread t(&actor::start_routine, this, child_pipe_, routine); t.detach(); signal sig; sig = parent_pipe_->wait(); assert(sig == signal::ok || sig == signal::ko); if (sig == signal::ko) { delete parent_pipe_; throw actor_initialization_exception(); } }
actor::actor(ActorStartRoutine routine) : parent_pipe_(nullptr) , child_pipe_(nullptr) , stopped_(false) { std::string pipe_endpoint; parent_pipe_ = new socket(actor_pipe_ctx_, socket_type::pair); pipe_endpoint = bind_parent(); child_pipe_ = new socket(actor_pipe_ctx_, socket_type::pair); child_pipe_->connect(pipe_endpoint); std::thread t(&actor::start_routine, this, child_pipe_, routine); t.detach(); signal sig; sig = parent_pipe_->wait(); assert(sig == signal::ok || sig == signal::ko); if (sig == signal::ko) { delete parent_pipe_; std::lock_guard<std::mutex> lg(mutex_); if (eptr_) { try { std::rethrow_exception(eptr_); } catch (std::exception &e) { std::throw_with_nested(actor_initialization_exception()); } } else { throw actor_initialization_exception(); } } }