实验5 结果不唯一的多线程并发运行实例

it2023-01-23  44

// // Created by macho-man on 2020/10/19. // #include <pthread.h> #include<stdio.h> void* printyou(void* unused) { int c=2000; while(c--) fputs("你",stderr); return NULL; } void* printme(void* unused) { int c=2000; while(c--) { fputs("我",stderr); } return NULL; } void* printhim(void* unused) { int c=2000; while(c--) fputs("他",stderr); return NULL; } int main() { int c=2000; pthread_t thread_id1,thread_id2,thread_id3; pthread_create(&thread_id1,NULL,&printyou,NULL); pthread_create(&thread_id2,NULL,&printme,NULL); pthread_create(&thread_id3,NULL,&printhim,NULL); while(c--) fputc('o',stderr); return 0; }
最新回复(0)