这程序哪里写错了
#include<stdio.h>#include<pthread.h>
char buffer[20];
char data[20];
pthread_mutex_t mutex;
pthread_cond_t con;
void write_buffer(void)
{
printf("-------%d\n",__LINE__);
scanf("%s",data);
pthread_mutex_lock(&mutex);
pthread_cond_signal(&con);
sprintf(buffer,"%s",data);
printf("-------%d\n",__LINE__);
pthread_mutex_unlock(&mutex);
}
void read_buffer(void)
{
printf("-------%d\n",__LINE__);
pthread_mutex_lock(&mutex);
pthread_cond_wait( &con, &mutex);
printf("-------%d\n",__LINE__);
printf("Read buffer,data=%s\n",buffer);
pthread_mutex_unlock(&mutex);
sleep(1);
}
int main(int argc,char **argv)
{
pthread_t reader,write;
pthread_mutex_init(&mutex,NULL);
pthread_create(&reader,NULL,(void *)(read_buffer),NULL);
pthread_create(&write,NULL,(void *)(write_buffer),NULL);
pthread_join(reader,NULL);
return 0;
}
[ 本帖最后由 xzy199999 于 2011-5-18 09:56 编辑 ]