Take the 2-minute tour ×  I am reading Thread Synchronization
from the book Advance Programming in unix environment.  In this
section, there is a example to use mutex with dynamically
allocated object. I have some doubts in the same.  Here I am
sharing a timeline of events (top to down) happening to explain
my doubts:    1. Thread1 created.   2. Thread1 create a mutex
var initialize it and put it on a global list so that other can
use it.   3. Now Thread1 acquired a lock to use a shared data
Structure say ds. Thread1 need to do very large amount of work
with ds, i.e. Thread1 is going to acquire this lock for a long
time.   4. Now while Thread1 still acquired the lock, Thread2 is
created.   5. Now Thread2 also want to use ds.   6. So Thread2
has to first increment the counter showing the reference to ds
is increased. To do so (according to the book) it first need to
acquire a lock using the same mutex_t variable before
incrementing the count.   7. But as Thread1 already acquired a
lock on this mutex_t variable