Thanks to the comments on my question, I ended up doing several things:
Stopped using operator[] in the read function and made the read function const.
Stopped using the condition_variable
Used shared_mutex based on the example in this other post.
The code:
map<std::string, double> collection;
mutable boost::shared_mutex collectionMutex;
...
//Write function:
void mapData()
{
// get upgradable access
boost::upgrade_lock<boost::shared_mutex> lock(collectionMutex);
// get exclusive access
boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
// Assignments here. Eg:
// collection["Some String"] = 0.0;
}
// Read function:
double readData(std::string name) const
{
double result = 0;
boost::shared_lock<boost::shared_mutex> lock(collectionMutex);
map<std::string, double>::const_iterator it = collection.find(name);
if(it != data.end())
{
result = it->second;
}
return result;
}