作业社区
探索学习新天地,共享知识资源!
weixin_慕九州3042664 的学生作业:
#include #include #include #include void *thread1_function(void *arg) { printf("Thread 1 is running, id is %ld\n", pthread_self()); pthread_detach(pthread_self()); return NULL; } void *thread2_function(void *arg) { printf("Thread 2 is running, id is %ld\n", pthread_self()); pthread_detach(pthread_self()); return NULL; } int main(void) { pthread_t thread1, thread2; int result; result = pthread_create(&thread1, NULL, thread1_function, NULL); if (result != 0) { fprintf(stderr, "Error creating thread 1: %d\n", result); return EXIT_FAILURE; } result = pthread_create(&thread2, NULL, thread2_function, NULL); if (result != 0) { fprintf(stderr, "Error creating thread 2: %d\n", result); return EXIT_FAILURE; } printf("Wait 3 seconds to let threads finish...\n"); sleep(3); return EXIT_SUCCESS; }
+6
weixin_慕九州3042664 的学生作业:
#include #include #include void *thread1_function(void *arg) { printf("Thread 1 is running, id is %ld\n", pthread_self()); return NULL; } void *thread2_function(void *arg) { printf("Thread 2 is running, id is %ld\n", pthread_self()); return NULL; } int main(void) { pthread_t thread1, thread2; int result; result = pthread_create(&thread1, NULL, thread1_function, NULL); if (result != 0) { fprintf(stderr, "Error creating thread 1: %d\n", result); return EXIT_FAILURE; } result = pthread_create(&thread2, NULL, thread2_function, NULL); if (result != 0) { fprintf(stderr, "Error creating thread 2: %d\n", result); return EXIT_FAILURE; } pthread_join(thread1, NULL); pthread_join(thread2, NULL); return EXIT_SUCCESS; }
+6