From 5e9b4c670dccf534490a0b2f6ebcb5fcb730c680 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Fri, 3 Oct 2025 18:03:17 +0200 Subject: [PATCH] add a test on thread create only --- thread.c => thread_c+j.c | 11 ++++---- thread_c.c | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) rename thread.c => thread_c+j.c (82%) create mode 100644 thread_c.c diff --git a/thread.c b/thread_c+j.c similarity index 82% rename from thread.c rename to thread_c+j.c index 92cec97..6e10272 100644 --- a/thread.c +++ b/thread_c+j.c @@ -13,13 +13,14 @@ dts_t *deltas = NULL; int nb_measurements = 0; -char *message = "thread"; +char *message = "Thread (create and join) latency"; void (*usage_ext) (FILE *) = NULL; int (*parse_arg_ext) (char *) = NULL; -void* dummy_thread(void *arg) { - (void)arg; - return NULL; + +void* dummy_thread (__attribute__((unused)) void *arg) +{ + pthread_exit (NULL); } int test (dts_t *buffer, int nb) @@ -48,7 +49,7 @@ int test (dts_t *buffer, int nb) ts_t ts2; sys_timestamp (&ts2); - deltas[i++] = diff_timestamp (&ts2, &ts1); + deltas[i] = diff_timestamp (&ts2, &ts1); } return 0; diff --git a/thread_c.c b/thread_c.c new file mode 100644 index 0000000..d237157 --- /dev/null +++ b/thread_c.c @@ -0,0 +1,55 @@ +/* depend: */ +/* cflags: */ +/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */ + +#include +#include + +#include "mtime.h" +#include "test.h" + +/* global variables */ + +dts_t *deltas = NULL; +int nb_measurements = 0; + +char *message = "Thread (create) latency"; +void (*usage_ext) (FILE *) = NULL; +int (*parse_arg_ext) (char *) = NULL; + +ts_t ts1, ts2; +int try = 0; + +void* dummy_thread (__attribute__((unused)) void *arg) +{ + sys_timestamp (&ts2); + pthread_exit (NULL); +} + +int test (dts_t *buffer, int nb) +{ + + /* set global variables */ + + deltas = buffer; + nb_measurements = nb; + + /* thread test */ + + for (int i = 0; i < nb_measurements; i++) { + + sys_timestamp (&ts1); + + pthread_t posix_t; + if (pthread_create(&posix_t, NULL, dummy_thread, NULL) != 0) { + fprintf (stderr, "error on pthread_create\n"); + return 1; + } + + pthread_join(posix_t, NULL); + + deltas[i] = diff_timestamp (&ts2, &ts1); + } + + return 0; +} -- 2.30.2