Lines Matching refs:mutex
12 * Provides errorchecking. A thread attempting to relock this mutex without unlocking it
13 * first will return with an error. A thread attempting to unlock a mutex which another
15 * mutex will return with an error.
20 * 3. Create a mutex with that mutexattr object.
21 * 4. Lock the mutex.
22 * 5. Create a thread, and in that thread, attempt to unlock the mutex. It should return an
35 pthread_mutex_t mutex;
38 int ret; /* Return value of the thread unlocking the mutex. */
42 /* Try to unlock the mutex that main already locked. */
43 ret=pthread_mutex_unlock(&mutex);
52 /* Initialize a mutex attributes object */
66 /* Initialize the mutex with that attribute obj. */
67 if(pthread_mutex_init(&mutex, &mta) != 0)
69 perror("Error intializing the mutex.\n");
73 /* Lock the mutex. */
74 if(pthread_mutex_lock(&mutex) != 0 )
76 perror("Error locking the mutex first time around.\n");
80 /* Create the thread that will try to unlock the mutex we just locked. */
92 printf("Test FAILED: Expected an error when trying to unlock a mutex that was locked by another thread. Returned 0 instead.\n");
97 pthread_mutex_unlock(&mutex);
98 pthread_mutex_destroy(&mutex);