Sign up ×

I have learnt C++ for a while and still didn't come across good book which would explain what are those beasts? Are they integral C++ feature? If so how is it that they are only mentioned in such book like The C++ Programming Language by B.S. If not, where can you get reliable information about them - prefferably a book (don't really like web tutorials), how to define them, how to use them etc. Thank you for any valuable help.

share|improve this question

closed as not constructive by Smi, WhozCraig, fancyPants, Leo, oezi Nov 16 '12 at 11:27


are you searching for how to use mutex concepts in c++? – Suresh Manchi Nov 26 '09 at 14:15
Locks and mutexes are a general programming concept; they are not specific to C++, and in fact, are not even a part of the current C++ language. – Charles Salvia Nov 26 '09 at 14:40
The new C++ revision, the C++11, includes locking primitives. E.g. look at the reference here – user283145 Nov 25 '11 at 20:33

5 Answers 5

up vote 9 down vote accepted

Locks and Mutexes are concurrency constructs used to ensure two threads won't access the same shared data at the same time, thus achieving correctness.

The current C++ standard doesn't feature concurrency tools.

Although you mentioned you prefer books to online tutorials, Herb Sutter's Effective Concurrency column is definitely a must read.

There is also Anthony Williams's upcoming book called C++ Concurrency in Action. Anthony Williams is the author of the Boost.Thread library.

Another threading library worth a look is Intel's TBB.

share|improve this answer
+1 for the Boost.Thread library, the classification of the concepts and the usages presented are worth reading, at least. – Matthieu M. Nov 26 '09 at 17:26
Threading facilities are now in C++11 also. See at this reference for example – user283145 Oct 16 '11 at 14:15

Locks and mutexes are not part of the current C++ standard, as they deal with concurrency which is not part of the standard. They are included in several libraries and various OSes have different ways of dealing with them (POSIX vs. Windows threads). If you pick up a book on concurrent programming for C++ you will probably find what you're looking for. You can find implementations for them in both the boost and ACE libraries.

Threads are part of the C++0x standard. I am not aware of any books for it yet but wikipedia has a blurb on the new threading features here.

share|improve this answer

C++ is not thread aware at this moment, so mutexes threads etc., are not part of the language.
Normally you'd need to use system specific libraries for threading and mutexes, like pthread library in Linux.
Maybe pthread-like libraries are too c-like, but there are C++ libraries that wrap them C++-way, like ptypes or boost.

share|improve this answer

They are basic constructs used to ensure correctness in parallel programs. They are included Boost and the new C++ standard.

I can recommend this book, although it doesn't focus on C++:

share|improve this answer

Locks and mutexes (think: mutual exclusion) allow cooperating threads to synchronize access to shared resources. For a brief overview of the concept, read the Wikipedia article on mutual exclusion.

These concepts are not part of the C++ language. The O'Reilly pthreads book would be a good reference for you, assuming you're on a POSIX platform. For Windows, you might go with Windows System Programming from Addison-Wesley.

share|improve this answer
