diff --git a/examples/ostest/cancel.c b/examples/ostest/cancel.c index b9085b958..25564c00f 100644 --- a/examples/ostest/cancel.c +++ b/examples/ostest/cancel.c @@ -168,7 +168,7 @@ static void restart_thread(pthread_t *waiter, int cancelable) /* Destroy the mutex */ printf("restart_thread: Destroying mutex\n"); - status = pthread_cond_destroy(&cond); + status = pthread_mutex_destroy(&mutex); if (status != 0) { printf("restart_thread: ERROR pthread_mutex_destroy failed, status=%d\n", status); diff --git a/examples/ostest/rmutex.c b/examples/ostest/rmutex.c index 62c64d48f..f7c0b8bc0 100644 --- a/examples/ostest/rmutex.c +++ b/examples/ostest/rmutex.c @@ -37,10 +37,6 @@ #include #include "ostest.h" -#ifndef NULL -# define NULL (void*)0 -#endif - #define NTHREADS 3 #define NLOOPS 3 #define NRECURSIONS 3 @@ -63,6 +59,26 @@ static void thread_inner(int id, int level) } printf("thread_inner[%d, %d]: Locked\n", id, level); + /* Try-lock already locked recursive mutex. */ + + status = pthread_mutex_trylock(&mut); + if (status != 0) + { + printf("thread_inner[%d, %d]: ERROR pthread_mutex_trylock failed: %d\n", + id, level, status); + } + else + { + /* Unlock the try-lock. */ + + status = pthread_mutex_unlock(&mut); + if (status != 0) + { + printf("thread_inner[%d, %d]: ERROR pthread_mutex_unlock after try-lock failed: %d\n", + id, level, status); + } + } + /* Give the other threads a chance */ pthread_yield(); @@ -131,7 +147,11 @@ void recursive_mutex_test(void) /* Initialize the mutex */ printf("recursive_mutex_test: Initializing mutex\n"); - pthread_mutex_init(&mut, &mattr); + status = pthread_mutex_init(&mut, &mattr); + if (status != 0) + { + printf("recursive_mutex_test: ERROR pthread_mutex_init failed, status=%d\n", status); + } /* Start the threads -- all at the same, default priority */ @@ -146,7 +166,7 @@ void recursive_mutex_test(void) #endif if (status != 0) { - printf("recursive_mutex_test: ERRROR thread#%d creation: %d\n", i+1, status); + printf("recursive_mutex_test: ERROR thread#%d creation: %d\n", i+1, status); } }