8 thread_add_one (void *arg
)
11 pthread_spinlock_t
*lock
= (pthread_spinlock_t
*) arg
;
13 /* When do_test holds the lock for 1 sec, the two thread will be
14 in contention for the lock. */
15 if (pthread_spin_lock (lock
) != 0)
17 puts ("thread_add_one(): spin_lock failed");
18 pthread_exit ((void *) 1l);
21 /* sleep 1s before modifying count */
26 if (pthread_spin_unlock (lock
) != 0)
28 puts ("thread_add_one(): spin_unlock failed");
29 pthread_exit ((void *) 1l);
39 pthread_spinlock_t lock
;
42 if (pthread_spin_init (&lock
, PTHREAD_PROCESS_PRIVATE
) != 0)
44 puts ("spin_init failed");
48 if (pthread_spin_lock (&lock
) != 0)
50 puts ("1st spin_lock failed");
54 if (pthread_create (&thr1
, NULL
, thread_add_one
, (void *) &lock
) != 0)
56 puts ("1st pthread_create failed");
60 if (pthread_create (&thr2
, NULL
, thread_add_one
, (void *) &lock
) != 0)
62 puts ("2nd pthread_create failed");
66 /* sleep 1s before modifying count */
71 if (pthread_spin_unlock (&lock
) != 0)
73 puts ("1st spin_unlock failed");
78 if (pthread_join (thr1
, &status
) != 0)
80 puts ("1st pthread_join failed");
85 puts ("failure in the 1st thread");
88 if (pthread_join (thr2
, &status
) != 0)
90 puts ("2nd pthread_join failed");
95 puts ("failure in the 2nd thread");
101 printf ("count is %d, should be 3\n", count
);
108 #define TEST_FUNCTION do_test ()
109 #include "../test-skeleton.c"