Dear All,
Can someone help me to understand why boost::thread::mutex is
noncopyable? I expect that there is a good reason, but I can't see it
at the moment.
In my multithreaded application I have a struct with some uninteresting
data in it, but I want updates to the struct as a whole to be atomic so
I have a mutex. For example:
struct person {
string firstname;
string surname;
mutex m;
};
I want to be able to put these structs in a container. Say a map:
map people;
person p;
people.insert(make_pair(1,p));
But I can't do this because the mutex is noncopyable and inserting
copies it.
Yes, I could have a map. But I don't understand why I'm
forced to do that.
Of course, copying a struct person while the mutex is locked would be a
bad thing to do. And copying the struct is not thread safe. But
higher-level constraints can prevent this sort of thing from happening;
for example, I might create my map while only one thread exists.
Can anyone offer any insight?
Thanks,
--Phil.