Opened 9 years ago

Last modified 9 years ago

#8540 new Bugs

Named Condition Variable hanging.

Reported by: ealfay@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.51.0 Severity: Problem
Keywords: Cc:

Description

Hi,

I am having problems with the shared memory code below. I can get this working on a Windows, MAC and OpenSUSE machine. However this same code does not work on my redhat v5.0 workstation machine.

It appears to hang on the wait (condition variable). Any idea why this would be the case on this particular OS? I can't find anything online on the subject.

Website of code: http://en.highscore.de/cpp/boost/interprocesscommunication.html#interprocesscommunication_managed_shared_memory

#include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/sync/named_mutex.hpp> #include <boost/interprocess/sync/named_condition.hpp> #include <boost/interprocess/sync/scoped_lock.hpp> #include <iostream>

int main() {

boost::interprocess::managed_shared_memory managed_shm(boost::interprocess::open_or_create, "shm", 1024); int *i = managed_shm.find_or_construct<int>("Integer")(0); boost::interprocess::named_mutex named_mtx(boost::interprocess::open_or_create, "mtx"); boost::interprocess::named_condition named_cnd(boost::interprocess::open_or_create, "cnd"); boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock(named_mtx); while (*i < 10) {

if (*i % 2 == 0) {

++(*i); named_cnd.notify_all(); named_cnd.wait(lock);

} else {

std::cout << *i << std::endl; ++(*i); named_cnd.notify_all(); named_cnd.wait(lock);

}

} named_cnd.notify_all(); boost::interprocess::shared_memory_object::remove("shm"); boost::interprocess::named_mutex::remove("mtx"); boost::interprocess::named_condition::remove("cnd");

}

Change History (1)

comment:1 by viboes, 9 years ago

Component: Noneinterprocess
Owner: set to Ion Gaztañaga
Note: See TracTickets for help on using tickets.