
作业社区
探索学习新天地,共享知识资源!
北城半夏4806197 的学生作业:
#include #include #include #include struct perosn{ char name[10]; int age; }; void *do_thread_one(void *arg) { static struct perosn mike; strcpy(mike.name, "Pual"); mike.age = 22; printf("Thread one start.\n"); pthread_exit((void *)&mike); } int main(void) { int err; pthread_t tid_one = 0; void *val = NULL; struct perosn* mkp; err = pthread_create(&tid_one,NULL,do_thread_one,NULL); if (err != 0){ fprintf(stderr,"[ERROR] pthread_create : < %s >\n",strerror(err)); exit(EXIT_FAILURE); } pthread_join(tid_one,&val); mkp = (struct perosn*)val; printf("name: age:\n",mkp->name,mkp->age); pthread_exit(NULL); }





北城半夏4806197 的学生作业:
#include #include #include #include void *do_thread_one(void *arg) { printf("Thread one start.\n"); pthread_exit(NULL); } void *do_thread_two(void *arg) { printf("Thread two start.\n"); pthread_exit(NULL); } int main(void) { int err; pthread_t tid_one = 0,tid_two = 0; err = pthread_create(&tid_one,NULL,do_thread_one,NULL); if (err != 0){ fprintf(stderr,"[ERROR] pthread_create : < %s >\n",strerror(err)); exit(EXIT_FAILURE); } err = pthread_create(&tid_two,NULL,do_thread_two,NULL); if (err != 0){ fprintf(stderr,"[ERROR] pthread_create : < %s >\n",strerror(err)); exit(EXIT_FAILURE); } pthread_detach(tid_one); pthread_detach(tid_two); printf("Main exit!\n"); pthread_exit(NULL); }





北城半夏4806197 的学生作业:
#include #include #include #include void *do_thread_one(void *arg) { printf("Thread one start.\n"); pthread_exit(NULL); } void *do_thread_two(void *arg) { printf("Thread two start.\n"); pthread_exit(NULL); } int main(void) { int err; pthread_t tid_one = 0,tid_two = 0; err = pthread_create(&tid_one,NULL,do_thread_one,NULL); if (err != 0){ fprintf(stderr,"[ERROR] pthread_create : < %s >\n",strerror(err)); exit(EXIT_FAILURE); } err = pthread_create(&tid_two,NULL,do_thread_two,NULL); if (err != 0){ fprintf(stderr,"[ERROR] pthread_create : < %s >\n",strerror(err)); exit(EXIT_FAILURE); } pthread_join(tid_one,NULL); pthread_join(tid_two,NULL); return 0; }




