Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Another easy test from McMini
[simgrid.git] / teshsuite / mc / mcmini / simple_threads_ok.c
diff --git a/teshsuite/mc/mcmini/simple_threads_ok.c b/teshsuite/mc/mcmini/simple_threads_ok.c
new file mode 100644 (file)
index 0000000..44c716c
--- /dev/null
@@ -0,0 +1,33 @@
+#include <pthread.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
+static void * thread_doit(void *unused) {
+    int len = (int) ((drand48() * 5) + 1);
+    sleep(len);
+    return NULL;
+}
+
+int main(int argc, char* argv[]) {
+    if(argc < 2) {
+        printf("Expected usage: %s THREAD_NUM\n", argv[0]);
+        return -1;
+    }
+
+    int thread_num = atoi(argv[1]);
+
+    pthread_t *threads = malloc(sizeof(pthread_t) * thread_num);
+
+    for(int i = 0; i < thread_num; i++) {
+        pthread_create(&threads[i], NULL, &thread_doit, NULL);
+    }
+
+    for(int i = 0; i < thread_num; i++) {
+        pthread_join(threads[i], NULL);
+    }
+
+    free(threads);
+
+    return 0;
+}