Boost::Interprocess mutex with condition variable

I'm trying to get a working implementation of a boost::interprocess
named_mutex with a named_condition_variable. I have created the following
toy console applications to try and understand what's necessary. The
console application 'Sleeper' is run first; it simply creates some resources
and then goes to sleep. Then 'Waker' is run with the intention that it
would cause the 'Sleeper' instance to resume execution and print out a
further message. Ultimately the intention is to have one Waker process and
several Sleeper processes.
When each application is run in a separate terminal window then the Sleeper
process sleeps and the Waker process tries to wake; but it is ineffective.
Can anyone advise what is wrong here and how to get the notify_all() to take
effect?
Thanks
Riskybiz.
// Sleeper.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include

One issue with your solution could be having a spurious wake up (http://vladimir_prus.blogspot.ca/2005/07/spurious-wakeups.html) after doing nc->wait(lock);. Wrapping this wait in a while loop will prevent that from happening. Another problem I can see is that your second process cleans up everything before your first process wakes up as nc->notify_all(); is not a blocking call. So the two problems I can see is that your first process could continue after the wait as its not in a loop due to spurious wake ups and if it does wait your second process will delete everything after the notify_all() call as it is running under a scoped mutex and so only after exiting from scope in process 2 will process 1 be able to claim the mutex but by now everything is deleted. -- View this message in context: http://boost.2283326.n4.nabble.com/Boost-Interprocess-mutex-with-condition-v... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Riskybiz
-
rudasi