当前位置: 技术问答>linux和unix
线程的问题,可能需要看代码??
来源: 互联网 发布时间:2015-06-13
本文导语: int msg=0; pthread_mutex_t mymutex=PTHREAD_MUTEX_INITIALIZER; pthread_cond_t mycond; void proc(void) { pthread_mutex_lock(&mymutex); if(msg==0) { printf("begin "); pthread_cond_wait(&mycond, &mymutex); printf("testn"); msg=1; } else { printf("i don`t kno...
int msg=0;
pthread_mutex_t mymutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t mycond;
void proc(void)
{
pthread_mutex_lock(&mymutex);
if(msg==0)
{
printf("begin ");
pthread_cond_wait(&mycond, &mymutex);
printf("testn");
msg=1;
}
else
{
printf("i don`t known");//这句应该不会被执行到??
}
pthread_mutex_unlock(&mymutex);
return;
}
void main()
{
pthread_t mythread;
int i;
if ( pthread_create( &mythread, NULL, proc, NULL) )
{ printf("error creating thread.");
abort();
}
pthread_cond_init(&mycond,NULL);
for ( i=0; i
pthread_mutex_t mymutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t mycond;
void proc(void)
{
pthread_mutex_lock(&mymutex);
if(msg==0)
{
printf("begin ");
pthread_cond_wait(&mycond, &mymutex);
printf("testn");
msg=1;
}
else
{
printf("i don`t known");//这句应该不会被执行到??
}
pthread_mutex_unlock(&mymutex);
return;
}
void main()
{
pthread_t mythread;
int i;
if ( pthread_create( &mythread, NULL, proc, NULL) )
{ printf("error creating thread.");
abort();
}
pthread_cond_init(&mycond,NULL);
for ( i=0; i