Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion thread/workerpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ limitations under the License.

#include <algorithm>
#include <future>
#include <mutex>
#include <random>
#include <thread>
#include <atomic>
Expand Down Expand Up @@ -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<std::mutex> lock(fini_mtx);
photon::fini();
}

void add_vcpu() {
Expand Down