Skip to main content

C/C++

The old fashioned that never gets old.

"In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg."

— Bjarne Stroustrup (creator of C++)

TODO: Import useful content from the references.

C++ Mutex

Mutex Type

  • Timed: The mutex can be locked with a timeout.
  • Recursive: The mutex can be locked multiple times by the same thread, for example, in a recursive function.
  • Shared: The mutex can be locked in shared mode by multiple threads, for example, for reading.
MutexTimedRecursiveShared
std::mutex
std::timed_mutex
std::recursive_mutex
std::recursive_timed_mutex
std::shared_mutex
std::shared_timed_mutex

Locking Functions

  • lock_guard: No-brainer, simple, single mutex locking.
  • scoped_lock: Locks multiple mutex at once.
  • unique_lock: Can unlock and relock the mutex when needed.
  • shared_lock: Shared (read) access with a shared mutex.

Misc

References