Why is boost::thread::mutex noncopyable?

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<int,person> 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<int,person*>. 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.

Phil Endecott wrote:
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.
http://www.boost.org/doc/html/threads/faq.html#id2786688 -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org
participants (2)
-
Phil Endecott
-
Rene Rivera