tags:

views:

429

answers:

5

Hi everyone, I learn 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.

+2  A: 

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.

Arkaitz Jimenez
+5  A: 

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.

tloach
+1  A: 

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++: http://www.amazon.com/Art-Multiprocessor-Programming-Maurice-Herlihy/dp/0123705916.

Bastien Léonard
+4  A: 

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.

Gregory Pakosz
+1 for the Boost.Thread library, the classification of the concepts and the usages presented are worth reading, at least.
Matthieu M.
+1  A: 

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.

Greg Bacon