diff --git a/thread/workerpool.cpp b/thread/workerpool.cpp index 9833794dc..57cf18c3f 100644 --- a/thread/workerpool.cpp +++ b/thread/workerpool.cpp @@ -23,6 +23,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -84,10 +85,16 @@ class WorkPool::impl { return vcpus.size(); } + // Serialize photon::fini() across workers. When all workers receive + // the shutdown signal simultaneously (via RingChannel), parallel + // vcpu teardown may race on shared state and cause SegFault. + std::mutex fini_mtx; + void worker_thread_routine(int ev_engine, int io_engine) { photon::init(ev_engine, io_engine); - DEFER(photon::fini()); main_loop(); + std::lock_guard lock(fini_mtx); + photon::fini(); } void add_vcpu() {