Skip to content

Commit

Permalink
region example: fix race between segment reset & presence check
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx authored and dennisklein committed Sep 8, 2022
1 parent 75e68e3 commit fdfde95
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/region/keep-alive.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <chrono>
#include <csignal>
#include <map>
#include <mutex>
#include <string>
#include <thread>

Expand Down Expand Up @@ -113,6 +114,7 @@ struct ShmManager

bool CheckPresence()
{
std::lock_guard<std::mutex> lock(localMtx);
for (const auto& sc : segmentCfgs) {
if (!(fair::mq::shmem::Monitor::SegmentIsPresent(fair::mq::shmem::ShmId{shmId}, sc.id))) {
return false;
Expand All @@ -128,6 +130,7 @@ struct ShmManager

void ResetContent()
{
std::lock_guard<std::mutex> lock(localMtx);
fair::mq::shmem::Monitor::ResetContent(fair::mq::shmem::ShmId{shmId}, segmentCfgs, regionCfgs);
}

Expand All @@ -145,6 +148,7 @@ struct ShmManager
}

std::string shmId;
std::mutex localMtx;
map<uint16_t, fair::mq::shmem::Segment> segments;
map<uint16_t, unique_ptr<fair::mq::shmem::UnmanagedRegion>> regions;
std::vector<fair::mq::shmem::SegmentConfig> segmentCfgs;
Expand Down

0 comments on commit fdfde95

Please sign in to comment.