simon 10 місяців тому
батько
коміт
64ec69d672
1 змінених файлів з 20 додано та 0 видалено
  1. 20 0
      test/thread_test.c

+ 20 - 0
test/thread_test.c

@@ -0,0 +1,20 @@
+// /usr/bin/gcc -g -Wall -Wextra -Werror -std=c17 -o thread_test.bin thread_test.c -lpthread
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+
+void *thread_function(void *_arg)
+{
+    unsigned int *arg = (unsigned int *)_arg;
+    printf(" new thread: my tid is %u\n", *arg);
+    return NULL;
+}
+
+int main()
+{
+    pthread_t thread;
+    pthread_create(&thread, NULL, thread_function, &thread); // pass the thread id to the new thread
+    printf("main thread: my tid is %lu\n", (unsigned long)pthread_self());
+    usleep(2000);
+    return 0;
+}