A few more mutex usage guidelines

In addition to the tips and guidelines that were provided earlier (refer to the Locking Guidelines section), think upon this as well:

  • How many locks should one use?
  • With many lock instances, how to know which lock variable to use and when?
  • Test whether a mutex is locked or not.

Let's take these points up one by one.

In small applications (like the kind shown here), perhaps using just a single lock to protect critical sections is enough; it has the advantage of keeping things simple (which is a big deal). However, in a large project, using just one lock to perform locking on every critical section one might encounter has the potential to become a major performance breaker! Think about why exactly this is: ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.