1、思维导图
https://www.zhixi.com/view/bed0eee2
2、作业
#include <my_h.h>
char buf[]="1234567";
void *A(void *a)
{
char s[100];
strcpy(s,*a);
while(1)
{
printf("%s\n",s);
}
}
void *B(void *b)
{
char s[100]=(char*)malloc(100);
strcpy(s,buf);
while(1)
{
int i=0,j=strlen(s)-1;
while(i>j)
{
char c=s[i];
s[i]=s[j];
s[j]=c;
i++;
j--;
}
free(s);
pthread_exit((void*)s);
}
}
int main(int argc, const char *argv[])
{
while(1)
{
pthread_t b;
if(pthread_create(&b,NULL,B,NULL)!=0)//创建B线程
{
printf("error:%d\n",__LINE__);
return -1;
}
char *s=NULL;
pthread_join(b,ptr);
pthread_t a;
if(pthread_create(&a,NULL,A,(void*)&s)!=0)//创建A线程
{
printf("error:%d\n",__LINE__);
return -1;
}
printf("--------------------------------------------------\n");
}
return 0;
}