add a test on thread create only
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 3 Oct 2025 16:03:17 +0000 (18:03 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 3 Oct 2025 16:03:17 +0000 (18:03 +0200)
thread.c [deleted file]
thread_c+j.c [new file with mode: 0644]
thread_c.c [new file with mode: 0644]

diff --git a/thread.c b/thread.c
deleted file mode 100644 (file)
index 92cec97..0000000
--- a/thread.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* depend: */
-/* cflags: */
-/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
-
-#include <pthread.h>
-#include <stdio.h>
-
-#include "mtime.h"
-#include "test.h"
-
-/* global variables */
-
-dts_t *deltas = NULL;
-int nb_measurements = 0;
-
-char *message = "thread";
-void (*usage_ext) (FILE *) = NULL;
-int (*parse_arg_ext) (char *) = NULL;
-
-void* dummy_thread(void *arg) {
-    (void)arg;
-    return 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++) {
-
-        ts_t ts1;
-        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);
-
-        ts_t ts2;
-        sys_timestamp (&ts2);
-
-        deltas[i++] = diff_timestamp (&ts2, &ts1);
-    }
-
-    return 0;
-}
diff --git a/thread_c+j.c b/thread_c+j.c
new file mode 100644 (file)
index 0000000..6e10272
--- /dev/null
@@ -0,0 +1,56 @@
+/* depend: */
+/* cflags: */
+/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+
+#include <pthread.h>
+#include <stdio.h>
+
+#include "mtime.h"
+#include "test.h"
+
+/* global variables */
+
+dts_t *deltas = NULL;
+int nb_measurements = 0;
+
+char *message = "Thread (create and join) latency";
+void (*usage_ext) (FILE *) = NULL;
+int (*parse_arg_ext) (char *) = NULL;
+
+
+void* dummy_thread (__attribute__((unused)) void *arg)
+{
+    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++) {
+
+        ts_t ts1;
+        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);
+
+        ts_t ts2;
+        sys_timestamp (&ts2);
+
+        deltas[i] = diff_timestamp (&ts2, &ts1);
+    }
+
+    return 0;
+}
diff --git a/thread_c.c b/thread_c.c
new file mode 100644 (file)
index 0000000..d237157
--- /dev/null
@@ -0,0 +1,55 @@
+/* depend: */
+/* cflags: */
+/* linker: mtime.o test.o stat.o -lm -lpthread -lrt */
+
+#include <pthread.h>
+#include <stdio.h>
+
+#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;
+}