Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
No need to duplicate functions.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 28 Jun 2022 09:40:37 +0000 (11:40 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 28 Jun 2022 19:56:21 +0000 (21:56 +0200)
examples/sthread/pthread-mutex-simple.c
examples/sthread/sthread-mutex-simple.c

index f0e29a6..3d9e995 100644 (file)
@@ -5,14 +5,7 @@
 
 pthread_mutex_t mutex;
 
-static void* thread1_fun(void* ignore)
-{
-  pthread_mutex_lock(&mutex);
-  pthread_mutex_unlock(&mutex);
-
-  return NULL;
-}
-static void* thread2_fun(void* ignore)
+static void* thread_fun(void* ignore)
 {
   pthread_mutex_lock(&mutex);
   pthread_mutex_unlock(&mutex);
@@ -28,9 +21,9 @@ int main(int argc, char* argv[])
 
   pthread_t thread1;
   pthread_t thread2;
-  pthread_create(&thread1, NULL, thread1_fun, NULL);
+  pthread_create(&thread1, NULL, thread_fun, NULL);
   fprintf(stderr, "here\n");
-  pthread_create(&thread2, NULL, thread2_fun, NULL);
+  pthread_create(&thread2, NULL, thread_fun, NULL);
   fprintf(stderr, "there\n");
   pthread_join(thread1, NULL);
   pthread_join(thread2, NULL);
index 45b6e51..3ab8267 100644 (file)
@@ -5,14 +5,7 @@
 
 sthread_mutex_t mutex;
 
-static void* thread1_fun(void* ignore)
-{
-  sthread_mutex_lock(&mutex);
-  sthread_mutex_unlock(&mutex);
-
-  return NULL;
-}
-static void* thread2_fun(void* ignore)
+static void* thread_fun(void* ignore)
 {
   sthread_mutex_lock(&mutex);
   sthread_mutex_unlock(&mutex);
@@ -26,8 +19,8 @@ int main(int argc, char* argv[])
 
   sthread_t thread1;
   sthread_t thread2;
-  sthread_create(&thread1, NULL, thread1_fun, NULL);
-  sthread_create(&thread2, NULL, thread2_fun, NULL);
+  sthread_create(&thread1, NULL, thread_fun, NULL);
+  sthread_create(&thread2, NULL, thread_fun, NULL);
   sthread_join(thread1, NULL);
   sthread_join(thread2, NULL);
   fprintf(stderr, "done\n");