Skip to content

Commit

Permalink
Fix the double-locking issue when spurious wakeup occurs in wait func…
Browse files Browse the repository at this point in the history
…tion.

Signed-off-by: Xiaojing Cao <[email protected]>
  • Loading branch information
xjzer authored and Xiaojing Cao committed Dec 6, 2024
1 parent 07638e5 commit 6c22f67
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/cpp/rtps/DataSharing/DataSharingListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,15 @@ DataSharingListener::~DataSharingListener()

void DataSharingListener::run()
{
std::unique_lock<Segment::mutex> lock(notification_->notification_->notification_mutex, std::defer_lock);
while (is_running_.load())
{
try
{
lock.lock();
std::unique_lock<Segment::mutex> lock(notification_->notification_->notification_mutex);
notification_->notification_->notification_cv.wait(lock, [&]
{
return !is_running_.load() || notification_->notification_->new_data.load();
});

lock.unlock();
}
catch (const boost::interprocess::interprocess_exception& /*e*/)
{
Expand Down

0 comments on commit 6c22f67

Please sign in to comment.