mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
fix(shmem): lock the region mutexes in one order
- GetRegion() locks the local region mutex first and then the session-wide shmem mutex; CreateRegion() locked them in the opposite order - a thread that creates a region and a thread that opens a region of another process in the same session can deadlock (ABBA) - lock the local region mutex first also in CreateRegion() - add a regression test Refs: #334 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -304,6 +304,8 @@ class Manager
|
||||
std::pair<UnmanagedRegion*, uint16_t> result;
|
||||
|
||||
{
|
||||
// lock order: fLocalRegionsMtx before fShmMtx (see GetRegion())
|
||||
std::lock_guard<std::mutex> lock(fLocalRegionsMtx);
|
||||
boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> shmLock(*fShmMtx);
|
||||
|
||||
if (!cfg.id.has_value()) {
|
||||
@@ -324,8 +326,6 @@ class Manager
|
||||
|
||||
const uint16_t id = cfg.id.value();
|
||||
|
||||
std::lock_guard<std::mutex> lock(fLocalRegionsMtx);
|
||||
|
||||
UnmanagedRegion* region = nullptr;
|
||||
|
||||
auto it = fRegions.find(id);
|
||||
@@ -407,7 +407,7 @@ class Manager
|
||||
|
||||
try {
|
||||
RegionConfig cfg;
|
||||
// get region info
|
||||
// get region info (lock order: fLocalRegionsMtx before fShmMtx)
|
||||
{
|
||||
boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> shmLock(*fShmMtx);
|
||||
RegionInfo regionInfo = fShmRegions->at(id);
|
||||
|
||||
Reference in New Issue
Block a user