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.
Thanks for the link. Here is the text: Why do Mutexes have noncopyable semantics? To ensure that deadlocks don't occur. The only logical form of copy would be to use some sort of shallow copy semantics in which multiple mutex objects could refer to the same mutex state. This means that if ObjA has a mutex object as part of its state and ObjB is copy constructed from it, then when ObjB::foo() locks the mutex it has effectively locked ObjA as well. This behavior can result in deadlock. Other copy semantics result in similar problems (if you think you can prove this to be wrong then supply us with an alternative and we'll reconsider). I disagree with the first comment: "The only logical form of copy would be to use some sort of shallow copy semantics in which multiple mutex objects could refer to the same mutex state." What's wrong with the copy of a mutex being a new independent mutex? (There's a problem if you copy a locked mutex, but I don't propose to do that.) --Phil.