In previous chapters that covered the usage of locks, you learned that locks don't lock anything; an insubstantial locking mechanism implemented on a data structure does not actually prevent external programs from accessing the data structure at the same time, by simply bypassing the lock imposed. One solution to this problem is to embed the lock into the data structure, so that it is impossible for the lock to be ignored by external entities.
In the first section of this chapter, we will consider the theories behind the preceding specific use of locks and lock-based data structures. Specifically, we will analyze the process of designing a concurrent counter that can be safely executed by different threads, using locks (or mutex) as the synchronization mechanism.