3

Mutex C++

 1 year ago
source link: https://carlosvin.github.io/langs/en/posts/cpp-mutex/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Mutex C++

Mutex wrapper on C++98 pthread mutex and a the better C++11 std::mutex solution

C++11 has added many improvements to help us developing multi-thread systems. I’m going to talk about Mutex.

In previous C++11 compiler versions, we can get a pthread Mutex, but we must initialize it and destroy it in old C style, in the end you must do more things than just lock/unlock.

With C++11 Mutex Class, we just lock/unclock the object.

If you still have to stick to previous C++11 compiler versions, maybe it is useful to you a wrapper class I created that helps you to work with pthread Mutex, so you just have to lock/unlock the Mutex object: Gist code.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK