2 /* Needed for older glibcs (2.3 and older, at least) who don't
3 otherwise "know" about pthread_rwlock_anything or about
4 PTHREAD_MUTEX_RECURSIVE (amongst things). */
13 /* Test of the mechanism for showing all locks held by a thread. This
14 is like locked_vs_unlocked.c, except that it uses a recursively
15 lockable lock, and one thread holds the lock more than once. Point
16 is to check that the lock showing mechanism shows the
17 lock-number-of-times-held count. */
23 void* child_fn1 ( void* arg
)
26 r
= pthread_mutex_lock(&mx
); assert(!r
);
27 r
= pthread_mutex_lock(&mx
); assert(!r
);
29 r
= pthread_mutex_unlock(&mx
); assert(!r
);
30 r
= pthread_mutex_unlock(&mx
); assert(!r
);
35 void* child_fn2 ( void* arg
)
42 int main ( int argc
, char** argv
)
45 pthread_t child1
, child2
;
46 pthread_mutexattr_t attr
;
47 r
= pthread_mutexattr_init( &attr
);
49 r
= pthread_mutexattr_settype( &attr
, PTHREAD_MUTEX_RECURSIVE
);
51 r
= pthread_mutex_init(&mx
, &attr
); assert(!r
);
53 r
= pthread_create(&child2
, NULL
, child_fn2
, NULL
); assert(!r
);
54 r
= pthread_create(&child1
, NULL
, child_fn1
, NULL
); assert(!r
);
56 r
= pthread_join(child1
, NULL
); assert(!r
);
57 r
= pthread_join(child2
, NULL
); assert(!r
);
59 r
= pthread_mutex_destroy(&mx
); assert(!r
);