1.主函数
int flag=0;
void* sun(void* agr){
while(1){
if(flag==1)
{
char arr[20]={0};
int fp2=open("1.txt",O_RDONLY);
if(fp2==-1){
perror("open");
return NULL;
}
read(fp2,arr,20);
puts(arr);
break;
}
}
}
int main(int argc, const char *argv[])
{
pthread_t thread;
pthread_t re=pthread_create(&thread,0,sun,0);
if (re!=0){
perror("create");
return 1;
}
char brr[20]={"qwerer"};
int fp1=open("1.txt",O_WRONLY|O_TRUNC|O_CREAT,0666);
if(fp1==-1){
perror("open");
return 1;
}
if(write(fp1,brr,20)!=-1){
flag=1;
}
void* ret;
pthread_join(thread,&ret);
return 0;
}
2.实现效果