From: Laurent MAZET Date: Tue, 7 Oct 2025 17:32:22 +0000 (+0200) Subject: prepare tests for affinity X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=19535e29545e77e17bc6cde52013941a81ca3de6;p=benchmarks.git prepare tests for affinity --- diff --git a/clock.c b/clock.c index 3a5a4b3..b563f42 100644 --- a/clock.c +++ b/clock.c @@ -1,7 +1,8 @@ /* depend: */ /* cflags: */ -/* linker: mtime.o test.o stat.o -lm -lrt */ +/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */ +#include #include #include #include @@ -13,6 +14,7 @@ dts_t *deltas = NULL; int nb_measurements = 0; +pthread_mutex_t *mutex = NULL; char *message = "Clock accurency"; void (*usage_ext) (FILE *) = NULL; @@ -23,15 +25,22 @@ int try = 0; #define MAXDUR 1000 #define MINDUR 100 -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; + mutex = synchro; - /* thread test */ + return 0; +} + +void *ping (__attribute__((unused)) void *arg) +{ + + pthread_mutex_unlock (mutex); for (int i = 0; i < nb_measurements; i++) { @@ -44,5 +53,16 @@ int test (dts_t *buffer, int nb) deltas[i] = diff_timestamp (&ts2, &ts1); } + pthread_exit (NULL); +} + +void *pong (__attribute__((unused)) void *arg) +{ + pthread_mutex_unlock (mutex); + pthread_exit (NULL); +} + +int finish () +{ return 0; } diff --git a/cycle.c b/cycle.c index 5ebc8e7..4f517d6 100644 --- a/cycle.c +++ b/cycle.c @@ -1,7 +1,8 @@ /* depend: */ /* cflags: */ -/* linker: mtime.o test.o stat.o -lm -lrt */ +/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */ +#include #include #include #include @@ -13,6 +14,7 @@ dts_t *deltas = NULL; int nb_measurements = 0; +pthread_mutex_t *mutex = NULL; char *message = "Cycle latency"; void (*usage_ext) (FILE *) = NULL; @@ -23,15 +25,22 @@ int try = 0; #define MAXDUR 1000 #define MINDUR 100 -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; + mutex = synchro; - /* thread test */ + return 0; +} + +void *ping (__attribute__((unused)) void *arg) +{ + + pthread_mutex_unlock (mutex); for (int i = 0; i < nb_measurements; i++) { @@ -44,5 +53,16 @@ int test (dts_t *buffer, int nb) deltas[i] = diff_timestamp (&ts2, &ts1) - duration; } + pthread_exit (NULL); +} + +void *pong (__attribute__((unused)) void *arg) +{ + pthread_mutex_unlock (mutex); + pthread_exit (NULL); +} + +int finish () +{ return 0; } diff --git a/mq_lat.c b/mq_lat.c index 4d62cbf..7a35124 100644 --- a/mq_lat.c +++ b/mq_lat.c @@ -2,6 +2,7 @@ /* cflags: */ /* linker: msg.o mtime.o test.o stat.o -lm -lpthread -lrt */ +#include #include #include #include @@ -26,28 +27,21 @@ char *message = "Message queue latency"; void (*usage_ext) (FILE *) = NULL; int (*parse_arg_ext) (char *) = NULL; +#define QNAME "/test_queue" #define MSGLEN 128 #define MAXBUF 1024 -#define TIMER 10000 +#define TIMER 1000 -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *mutex = NULL; ts_t ts1, ts2; int rc = 0; void *ping (__attribute__((unused)) void *arg) { - /* open mq */ - - struct mq_attr attr; - attr.mq_flags = 0; - attr.mq_maxmsg = 5; - attr.mq_msgsize = MAXBUF; - attr.mq_curmsgs = 0; - - mqd_t mq = mq_open ("/test_queue", O_CREAT | O_RDWR, 0644, &attr); - if (mq == -1) { - fprintf (stderr, "ping: mq_open\n"); + mqd_t mq_out = mq_open (QNAME, O_WRONLY); + if (mq_out == -1) { + fprintf (stderr, "ping error: mq_open\n"); rc = 1; pthread_exit (NULL); } @@ -56,19 +50,18 @@ void *ping (__attribute__((unused)) void *arg) printf ("Sending ping...\n"); - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (mutex); usleep (TIMER); for (int i = 0; i < nb_measurements; i++) { - //char *msg = "ping"; char *msg = get_msg (MSGLEN); - pthread_mutex_lock (&mutex); - pthread_mutex_unlock (&mutex); + pthread_mutex_lock (mutex); + pthread_mutex_unlock (mutex); sys_timestamp (&ts1); - if (mq_send (mq, msg, strlen (msg) + 1, 0) == -1) { + if (mq_send (mq_out, msg, MSGLEN, 0) == -1) { fprintf (stderr, "ping error: mq_send (%d)\n", i); rc = 1; pthread_exit (NULL); @@ -76,7 +69,7 @@ void *ping (__attribute__((unused)) void *arg) usleep (TIMER); } - mq_close (mq); + mq_close (mq_out); pthread_exit (NULL); } @@ -84,79 +77,76 @@ void *ping (__attribute__((unused)) void *arg) void *pong (__attribute__((unused)) void *arg) { - /* open mq */ - - struct mq_attr attr; - attr.mq_flags = 0; - attr.mq_maxmsg = 5; - attr.mq_msgsize = MAXBUF; - attr.mq_curmsgs = 0; - - mqd_t mq = mq_open ("/test_queue", O_CREAT | O_RDWR, 0644, &attr); - if (mq == -1) { - fprintf (stderr, "ping: mq_open\n"); + mqd_t mq_in = mq_open (QNAME, O_RDONLY); + if (mq_in == -1) { + fprintf (stderr, "error pong: mq_open\n"); rc = 1; pthread_exit (NULL); } - /* main loop */ - printf ("Responding pong...\n"); for (int i = 0; i < nb_measurements; i++) { - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (mutex); char buffer[MAXBUF] = { 0 }; - if (mq_receive (mq, buffer, sizeof (buffer) - 1, NULL) == -1) { + if (mq_receive (mq_in, buffer, sizeof (buffer), NULL) == -1) { fprintf (stderr, "pong error: mq_receive (%d)\n", i); rc = 1; pthread_exit (NULL); } + sys_timestamp (&ts2); deltas[i] = diff_timestamp (&ts2, &ts1); - pthread_mutex_lock (&mutex); + pthread_mutex_lock (mutex); usleep (TIMER); } - mq_close (mq); + mq_close (mq_in); pthread_exit (NULL); } -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; + mutex = synchro; - /* mq latency test */ + /* open mq */ - pthread_mutex_lock (&mutex); + struct mq_attr mq_attr = { 0 }; + mq_attr.mq_flags = 0; + mq_attr.mq_maxmsg = 5; + mq_attr.mq_msgsize = MAXBUF; + mq_attr.mq_curmsgs = 0; - pthread_t tid1; - if (pthread_create (&tid1, NULL, ping, NULL) != 0) { - fprintf (stderr, "error on pthread_create\n"); + if ((mq_unlink (QNAME) != 0) && errno != ENOENT) { + fprintf (stderr, "error: mq_unlink\n"); return 1; } - - pthread_mutex_lock (&mutex); - - pthread_t tid2; - if (pthread_create (&tid2, NULL, pong, NULL) != 0) { - fprintf (stderr, "error on pthread_create\n"); + mqd_t mq = mq_open (QNAME, O_CREAT | O_RDWR, S_IWUSR | S_IRUSR, &mq_attr); + if (mq == -1) { + fprintf (stderr, "error: mq_open\n"); return 1; } + mq_close (mq); - pthread_join (tid1, NULL); - pthread_join (tid2, NULL); + return 0; +} - mq_unlink ("/test_queue"); +int finish () +{ - pthread_mutex_destroy (&mutex); + if ((mq_unlink (QNAME) != 0) && errno != ENOENT) { + fprintf (stderr, "error: mq_unlink\n"); + return 1; + } return rc; } diff --git a/mutex.c b/mutex.c index 6dba569..a9a5581 100644 --- a/mutex.c +++ b/mutex.c @@ -18,7 +18,8 @@ char *message = "Mutex latency"; void (*usage_ext) (FILE *) = NULL; int (*parse_arg_ext) (char *) = NULL; -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *mutex = NULL; +pthread_mutex_t test = PTHREAD_MUTEX_INITIALIZER; volatile int shared_flag = 0; ts_t ts1, ts2; int try = 0; @@ -26,43 +27,33 @@ int nbtoofast = 0; #define TIMER 1000 -void *mutex_giver_task (__attribute__((unused)) void *arg) +void *ping (__attribute__((unused)) void *arg) { + pthread_mutex_unlock (mutex); + while (try < nb_measurements) { - pthread_mutex_lock (&mutex); + pthread_mutex_lock (&test); usleep (TIMER); shared_flag = 1; sys_timestamp (&ts1); - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (&test); //shared_flag = 0; usleep (TIMER); } + pthread_exit (NULL); } -void *mutex_taker_task (__attribute__((unused)) void *arg) +void *pong (__attribute__((unused)) void *arg) { - /* real-time process */ -/* - struct sched_param param = {0}; - if (sched_getparam (0, ¶m) != 0) { - fprintf (stderr, "error: sched_getparam\n"); - return 1; - } - param.sched_priority += 10; - int rc = sched_setscheduler (0, SCHED_FIFO, ¶m); - if (rc != 0) { - fprintf (stderr, "error: sched_setscheduler\n"); - return 1; - } -*/ + pthread_mutex_unlock (mutex); while (try < nb_measurements) { ts_t ts; sys_timestamp (&ts); - pthread_mutex_lock (&mutex); + pthread_mutex_lock (&test); if (shared_flag) { sys_timestamp (&ts2); if (diff_timestamp (&ts2, &ts) < (9 * TIMER / 10)) { @@ -72,42 +63,32 @@ void *mutex_taker_task (__attribute__((unused)) void *arg) } shared_flag = 0; } - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (&test); } pthread_exit (NULL); } -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; - - /* mutex test */ + mutex = synchro; shared_flag = 1; - pthread_t giver_thread; - if (pthread_create (&giver_thread, NULL, mutex_giver_task, NULL) != 0) { - fprintf (stderr, "error on pthread_create for giver_task\n"); - return 1; - } - - pthread_t taker_thread; - if (pthread_create (&taker_thread, NULL, mutex_taker_task, NULL) != 0) { - fprintf (stderr, "error on pthread_create for taker_task\n"); - return 1; - } + return 0; +} - pthread_join (giver_thread, NULL); - pthread_join (taker_thread, NULL); +int finish () +{ - pthread_mutex_destroy (&mutex); + pthread_mutex_destroy (&test); printf ("Too fast: %d\n", nbtoofast); - return 0; + return nbtoofast; } diff --git a/pipe_lat.c b/pipe_lat.c index 3d7aae0..a93630f 100644 --- a/pipe_lat.c +++ b/pipe_lat.c @@ -26,7 +26,7 @@ int (*parse_arg_ext) (char *) = NULL; #define MAXBUF 1024 #define TIMER 1000 -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *mutex = NULL; ts_t ts1, ts2; int pipefd[2] = { 0 }; int rc = 0; @@ -41,15 +41,15 @@ void *ping (__attribute__((unused)) void *arg) printf ("Sending ping...\n"); - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (mutex); usleep (TIMER); for (int i = 0; i < nb_measurements; i++) { char *msg = get_msg (MSGLEN); - pthread_mutex_lock (&mutex); - pthread_mutex_unlock (&mutex); + pthread_mutex_lock (mutex); + pthread_mutex_unlock (mutex); sys_timestamp (&ts1); if (write (fdout, msg, MSGLEN) == -1) { @@ -76,11 +76,11 @@ void *pong (__attribute__((unused)) void *arg) for (int i = 0; i < nb_measurements; i++) { - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (mutex); char buffer[MAXBUF] = { 0 }; if (read (fdin, buffer, sizeof(buffer)) == -1) { - fprintf (stderr, "ping error: read (%d)\n", i); + fprintf (stderr, "pong error: read (%d)\n", i); rc = 1; pthread_exit (NULL); } @@ -88,7 +88,7 @@ void *pong (__attribute__((unused)) void *arg) sys_timestamp (&ts2); deltas[i] = diff_timestamp (&ts2, &ts1); - pthread_mutex_lock (&mutex); + pthread_mutex_lock (mutex); usleep (TIMER); } @@ -98,13 +98,14 @@ void *pong (__attribute__((unused)) void *arg) pthread_exit (NULL); } -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; + mutex = synchro; /* open pipe */ @@ -113,31 +114,14 @@ int test (dts_t *buffer, int nb) return 1; } - /* pipe test */ - - pthread_mutex_lock (&mutex); - - pthread_t tid1; - if (pthread_create (&tid1, NULL, ping, NULL) != 0) { - fprintf (stderr, "error on pthread_create\n"); - return 1; - } - - pthread_mutex_lock (&mutex); - - pthread_t tid2; - if (pthread_create (&tid2, NULL, pong, NULL) != 0) { - fprintf (stderr, "error on pthread_create\n"); - return 1; - } + return 0; +} - pthread_join (tid1, NULL); - pthread_join (tid2, NULL); +int finish () +{ close (pipefd[0]); close (pipefd[1]); - pthread_mutex_destroy (&mutex); - return rc; } diff --git a/semaphore.c b/semaphore.c index ac0202c..21d2827 100644 --- a/semaphore.c +++ b/semaphore.c @@ -22,7 +22,7 @@ char *message = "Semaphore latency"; void (*usage_ext) (FILE *) = NULL; int (*parse_arg_ext) (char *) = NULL; -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *mutex = NULL; volatile int shared_flag = 0; ts_t ts1, ts2; sem_t sem; @@ -31,9 +31,11 @@ int nbtoofast = 0; #define TIMER 1000 -void *semaphore_giver_task (__attribute__((unused)) void *arg) +void *ping (__attribute__((unused)) void *arg) { + pthread_mutex_unlock (mutex); + while (try < nb_measurements) { sem_wait (&sem); usleep (TIMER); @@ -47,9 +49,11 @@ void *semaphore_giver_task (__attribute__((unused)) void *arg) pthread_exit (NULL); } -void *semaphore_taker_task (__attribute__((unused)) void *arg) +void *pong (__attribute__((unused)) void *arg) { + pthread_mutex_unlock (mutex); + while (try < nb_measurements) { ts_t ts; sys_timestamp (&ts); @@ -69,13 +73,14 @@ void *semaphore_taker_task (__attribute__((unused)) void *arg) pthread_exit (NULL); } -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; + mutex = synchro; /* semaphore test */ @@ -83,24 +88,15 @@ int test (dts_t *buffer, int nb) shared_flag = 1; - pthread_t giver_thread; - if (pthread_create (&giver_thread, NULL, semaphore_giver_task, NULL) != 0) { - fprintf (stderr, "error on pthread_create for giver_task\n"); - return 1; - } - - pthread_t taker_thread; - if (pthread_create (&taker_thread, NULL, semaphore_taker_task, NULL) != 0) { - fprintf (stderr, "error on pthread_create for taker_task\n"); - return 1; - } + return 0; +} - pthread_join (giver_thread, NULL); - pthread_join (taker_thread, NULL); +int finish () +{ sem_destroy (&sem); printf ("Too fast: %d\n", nbtoofast); - return 0; + return nbtoofast; } diff --git a/test.c b/test.c index 838698f..c74d681 100644 --- a/test.c +++ b/test.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -168,7 +169,35 @@ int main (int argc, char *argv[]) printf ("Test: %s\n", (message) ? message : "unknown"); - if (test (buffer, nb)) { + pthread_mutex_t synchro = PTHREAD_MUTEX_INITIALIZER; + + if (init (buffer, nb, &synchro)) { + fprintf (stderr, "error on init\n"); + return 1; + } + + pthread_mutex_lock (&synchro); + + pthread_t tid1; + if (pthread_create (&tid1, NULL, ping, NULL) != 0) { + fprintf (stderr, "error on pthread_create\n"); + return 1; + } + + pthread_mutex_lock (&synchro); + + pthread_t tid2; + if (pthread_create (&tid2, NULL, pong, NULL) != 0) { + fprintf (stderr, "error on pthread_create\n"); + return 1; + } + + pthread_join (tid1, NULL); + pthread_join (tid2, NULL); + + pthread_mutex_destroy (&synchro); + + if (finish ()) { printf ("\033[1;31mKO\033[0;0m\n"); return 1; } else { diff --git a/test.h b/test.h index 8faa05d..dab521d 100644 --- a/test.h +++ b/test.h @@ -3,8 +3,16 @@ #ifndef __TEST_H__ #define __TEST_H__ +#include + #include "mtime.h" -int test (dts_t *buffer, int nb); +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro); + +void *ping (void *arg); + +void *pong (void *arg); + +int finish (); #endif /* __TEST_H__ */ diff --git a/thread_c+j.c b/thread_c+j.c index 6e10272..5b752b0 100644 --- a/thread_c+j.c +++ b/thread_c+j.c @@ -12,26 +12,35 @@ dts_t *deltas = NULL; int nb_measurements = 0; +pthread_mutex_t *mutex = NULL; char *message = "Thread (create and join) latency"; void (*usage_ext) (FILE *) = NULL; int (*parse_arg_ext) (char *) = NULL; +int rc = 0; -void* dummy_thread (__attribute__((unused)) void *arg) -{ - pthread_exit (NULL); -} - -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; + mutex = synchro; + + return 0; +} + +void* dummy_thread (__attribute__((unused)) void *arg) +{ + pthread_exit (NULL); +} + +void *ping (__attribute__((unused)) void *arg) +{ - /* thread test */ + pthread_mutex_unlock (mutex); for (int i = 0; i < nb_measurements; i++) { @@ -41,7 +50,8 @@ int test (dts_t *buffer, int nb) pthread_t posix_t; if (pthread_create(&posix_t, NULL, dummy_thread, NULL) != 0) { fprintf (stderr, "error on pthread_create\n"); - return 1; + rc = 1; + pthread_exit (NULL); } pthread_join(posix_t, NULL); @@ -52,5 +62,16 @@ int test (dts_t *buffer, int nb) deltas[i] = diff_timestamp (&ts2, &ts1); } - return 0; + pthread_exit (NULL); +} + +void *pong (__attribute__((unused)) void *arg) +{ + pthread_mutex_unlock (mutex); + pthread_exit (NULL); +} + +int finish () +{ + return rc; } diff --git a/thread_c.c b/thread_c.c index d237157..637c526 100644 --- a/thread_c.c +++ b/thread_c.c @@ -12,13 +12,26 @@ dts_t *deltas = NULL; int nb_measurements = 0; +pthread_mutex_t *mutex = NULL; char *message = "Thread (create) latency"; void (*usage_ext) (FILE *) = NULL; int (*parse_arg_ext) (char *) = NULL; ts_t ts1, ts2; -int try = 0; +int rc = 0; + +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) +{ + + /* set global variables */ + + deltas = buffer; + nb_measurements = nb; + mutex = synchro; + + return 0; +} void* dummy_thread (__attribute__((unused)) void *arg) { @@ -26,15 +39,10 @@ void* dummy_thread (__attribute__((unused)) void *arg) pthread_exit (NULL); } -int test (dts_t *buffer, int nb) +void *ping (__attribute__((unused)) void *arg) { - /* set global variables */ - - deltas = buffer; - nb_measurements = nb; - - /* thread test */ + pthread_mutex_unlock (mutex); for (int i = 0; i < nb_measurements; i++) { @@ -43,7 +51,8 @@ int test (dts_t *buffer, int nb) pthread_t posix_t; if (pthread_create(&posix_t, NULL, dummy_thread, NULL) != 0) { fprintf (stderr, "error on pthread_create\n"); - return 1; + rc = 1; + pthread_exit (NULL); } pthread_join(posix_t, NULL); @@ -51,5 +60,16 @@ int test (dts_t *buffer, int nb) deltas[i] = diff_timestamp (&ts2, &ts1); } - return 0; + pthread_exit (NULL); +} + +void *pong (__attribute__((unused)) void *arg) +{ + pthread_mutex_unlock (mutex); + pthread_exit (NULL); +} + +int finish () +{ + return rc; } diff --git a/udp_lat.c b/udp_lat.c index ab7499e..3b47f8d 100644 --- a/udp_lat.c +++ b/udp_lat.c @@ -52,7 +52,7 @@ int (*parse_arg_ext) (char *) = _parse_arg_ext; #define MAXBUF 1024 #define TIMER 1000 -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t *mutex = NULL; ts_t ts1, ts2; int rc = 0; int localhost_ip = 0x7f000001; @@ -85,15 +85,15 @@ void *ping (__attribute__((unused)) void *arg) printf ("Sending ping...\n"); - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (mutex); usleep (TIMER); for (int i = 0; i < nb_measurements; i++) { char *msg = get_msg (MSGLEN); - pthread_mutex_lock (&mutex); - pthread_mutex_unlock (&mutex); + pthread_mutex_lock (mutex); + pthread_mutex_unlock (mutex); sys_timestamp (&ts1); if (sendto (sock, msg, MSGLEN, 0, (struct sockaddr *)&remote, sizeof (remote)) == -1) { @@ -135,7 +135,7 @@ void *pong (__attribute__((unused)) void *arg) for (int i = 0; i < nb_measurements; i++) { - pthread_mutex_unlock (&mutex); + pthread_mutex_unlock (mutex); char buffer[MAXBUF] = { 0 }; if (recv (sock, buffer, MAXBUF, 0) == -1) { @@ -146,7 +146,7 @@ void *pong (__attribute__((unused)) void *arg) sys_timestamp (&ts2); deltas[i] = diff_timestamp (&ts2, &ts1); - pthread_mutex_lock (&mutex); + pthread_mutex_lock (mutex); usleep (TIMER); } @@ -155,36 +155,19 @@ void *pong (__attribute__((unused)) void *arg) pthread_exit (NULL); } -int test (dts_t *buffer, int nb) +int init (dts_t *buffer, int nb, pthread_mutex_t *synchro) { /* set global variables */ deltas = buffer; nb_measurements = nb; + mutex = synchro; - /* udp socket test */ - - pthread_mutex_lock (&mutex); - - pthread_t tid1; - if (pthread_create (&tid1, NULL, ping, NULL) != 0) { - fprintf (stderr, "error on pthread_create\n"); - return 1; - } - - pthread_mutex_lock (&mutex); - - pthread_t tid2; - if (pthread_create (&tid2, NULL, pong, NULL) != 0) { - fprintf (stderr, "error on pthread_create\n"); - return 1; - } - - pthread_join (tid1, NULL); - pthread_join (tid2, NULL); - - pthread_mutex_destroy (&mutex); + return 0; +} +int finish () +{ return rc; }