当前位置: 技术问答>linux和unix
线程的问题,可能需要看代码??(new)
来源: 互联网 发布时间:2015-06-14
本文导语: pthread_mutex_t mymutex=PTHREAD_MUTEX_INITIALIZER; pthread_cond_t mycond; void *proc(void *arg) { while(1) { pthread_mutex_lock(&mymutex); //lock printf("begin "); pthread_cond_wait(&mycond, &mymutex); printf("testn"); pthread_m...
pthread_mutex_t mymutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t mycond;
void *proc(void *arg)
{
while(1)
{
pthread_mutex_lock(&mymutex); //lock
printf("begin ");
pthread_cond_wait(&mycond, &mymutex);
printf("testn");
pthread_mutex_unlock(&mymutex);
}
}
int main(int argc, char *argv[])
{
pthread_t mythread;
int i;
if ( pthread_create( &mythread, NULL, proc, NULL) )
{
printf("error creating thread.");
abort();
}
pthread_cond_init(&mycond,NULL); //initialize
sleep(1);
for ( i=0; i
pthread_cond_t mycond;
void *proc(void *arg)
{
while(1)
{
pthread_mutex_lock(&mymutex); //lock
printf("begin ");
pthread_cond_wait(&mycond, &mymutex);
printf("testn");
pthread_mutex_unlock(&mymutex);
}
}
int main(int argc, char *argv[])
{
pthread_t mythread;
int i;
if ( pthread_create( &mythread, NULL, proc, NULL) )
{
printf("error creating thread.");
abort();
}
pthread_cond_init(&mycond,NULL); //initialize
sleep(1);
for ( i=0; i