Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is lock_guard a template?

I just learned about lock_guard and I was wondering why it is a template. Until now I have only seen std::lock_guard<std::mutex> with std::mutex inside the angle brackets.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Using std::lock_guard<std::mutex> is indeed quite common.
But you can use std::lock_guard with other mutex types:

  1. Various standard mutex types, e.g.: std::recursive_mutex.
  2. Your own mutex type. You can use any type, as long as it is a BasicLockable, i.e. it supports the required methods: lock(), unlock().
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading