about summary refs log tree commit diff
path: root/linuxthreads/Examples/ex17.c
diff options
context:
space:
mode:
Diffstat (limited to 'linuxthreads/Examples/ex17.c')
-rw-r--r--linuxthreads/Examples/ex17.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/linuxthreads/Examples/ex17.c b/linuxthreads/Examples/ex17.c
index f5c99ee3fb..a3ab909990 100644
--- a/linuxthreads/Examples/ex17.c
+++ b/linuxthreads/Examples/ex17.c
@@ -6,9 +6,12 @@
 #include <limits.h>
 #include <sys/mman.h>
 
+static pthread_mutex_t synch = PTHREAD_MUTEX_INITIALIZER;
+
 static void *
 test_thread (void *v_param)
 {
+  pthread_mutex_lock (&synch);
   return NULL;
 }
 
@@ -56,6 +59,13 @@ main (void)
       return 2;
     }
 
+  status = pthread_mutex_lock (&synch);
+  if (status != 0)
+    {
+      printf ("cannot get lock: %s\n", strerror (status));
+      return 1;
+    }
+
   status = pthread_create (&thread, &attr, test_thread, NULL);
   if (status != 0)
     {
@@ -85,6 +95,13 @@ main (void)
       return 3;
     }
 
+  status = pthread_mutex_unlock (&synch);
+  if (status != 0)
+    {
+      printf ("cannot release lock: %s\n", strerror (status));
+      return 1;
+    }
+
   /* pthread_detach (thread); */
   if (pthread_join (thread, NULL) != 0)
     {