MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / ensure_worker_alive

Function ensure_worker_alive

src/core/impl/system.cpp:454–473  ·  view source on GitHub ↗

start worker if it is not alive

Source from the content-addressed store, hash-verified

452
453 //! start worker if it is not alive
454 void ensure_worker_alive() {
455 if (check_worker_alive())
456 return;
457
458 auto name = ssprintf(
459 "megbrain/%d/TimedFuncInvoker/%d", getpid(), m_sock_name_cnt++);
460 mgb_log_debug("start worker process on socket %s", name.c_str());
461
462 create_sock_and_bind(name.c_str(), ::bind);
463 CHECK_SYS_ERR(listen(m_sock_fd, 1));
464
465 m_worker_pid = m_fork_exec_impl(name.c_str());
466 mgb_assert(m_worker_pid > 0);
467 m_peer_fd = accept(m_sock_fd, nullptr, nullptr);
468 CHECK_SYS_ERR(m_peer_fd);
469
470 uint32_t hello = time(nullptr);
471 write_pod(hello);
472 mgb_assert(read_pod<uint32_t>() == hello + 1);
473 }
474
475 Maybe<Result> invoke(FuncId id, const Param& param, double timeout) override {
476 MGB_LOCK_GUARD(m_global_mtx);

Callers 1

invokeFunction · 0.85

Calls 1

check_worker_aliveFunction · 0.85

Tested by

no test coverage detected