#include<stdio.h>#include<stdlib.h>#include<string.h>#include<assert.h>#include<unistd.h>#include<pthread.h>void*pthread_fun(void* arg){char buff[]="a b c d e f g h i j k";char* p =strtok(buff," ");while(p !=NULL){printf("fun:%s\n",p);p =strtok(NULL," ");sleep(1);}pthread_exit(NULL);}intmain(){pthread_t id;int res =pthread_create(&id,NULL,pthread_fun,NULL);assert(res ==0);char buff[]="1 2 3 4 5 6 7 8 9 10";char*p =strtok(buff," ");while(p !=NULL){printf("main:%s\n",p);p =strtok(NULL," ");sleep(1);}char* s =NULL;pthread_join(id,(void**)s);exit(0);}
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<assert.h>#include<unistd.h>#include<pthread.h>void*pthread_fun(void* arg){char buff[]="a b c d e f g h i j k";char* q =NULL;char* p =strtok_r(buff," ",&q);while(p !=NULL){printf("fun:%s\n",p);p =strtok_r(NULL," ",&q);sleep(1);}pthread_exit(NULL);}intmain(){pthread_t id;int res =pthread_create(&id,NULL,pthread_fun,NULL);assert(res ==0);char buff[]="1 2 3 4 5 6 7 8 9 10";char*q =NULL;char*p =strtok_r(buff," ",&q);while(p !=NULL){printf("main:%s\n",p);p =strtok_r(NULL," ",&q);sleep(1);}char* s =NULL;pthread_join(id,(void**)s);exit(0);}