1 
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <assert.h>
6 
7 /* The simplest possible test that triggers a lock order acquisition
8    error. */
9 
10 int main ( void )
11 {
12    int r;
13    pthread_mutex_t mx1, mx2;
14    r = pthread_mutex_init( &mx1, NULL ); assert(r==0);
15    r = pthread_mutex_init( &mx2, NULL ); assert(r==0);
16 
17    r = pthread_mutex_lock( &mx1 ); assert(r==0);
18    r = pthread_mutex_lock( &mx2 ); assert(r==0);
19 
20    r = pthread_mutex_unlock( &mx1 ); assert(r==0);
21    r = pthread_mutex_unlock( &mx2 ); assert(r==0);
22 
23    r = pthread_mutex_lock( &mx2 ); assert(r==0); /* error */
24    r = pthread_mutex_lock( &mx1 ); assert(r==0);
25 
26    r = pthread_mutex_unlock( &mx1 ); assert(r==0);
27    r = pthread_mutex_unlock( &mx2 ); assert(r==0);
28 
29    r = pthread_mutex_destroy( &mx1 );
30    r = pthread_mutex_destroy( &mx2 );
31 
32    return 0;
33 }
34