Home > OS >  A great god USES pthread_join period of mistakes for help all of you!
A great god USES pthread_join period of mistakes for help all of you!

Time:09-30

Code:
#include
#include
#include
#include
# define N 3
Void * thrd_func (void * arg)
{
Int thrd_num=(int) arg;
Int delay_time=1;
Int count=0;

Printf (" thead % d is starting \ n ", thrd_num);
For (count=0; Count<5; Count++)
{
//delay_time=(int) (rand () * 6.0/(RAND_MAX)) + 1;
Delay_time=thrd_num + 1;
Sleep (delay_time);
Printf (" \ t thread % d: job % d delay \ n ", thrd_num, delay_time);
}
Printf (" thread % d finished \ n ", thrd_num);
Pthread_exit (NULL);
}
Int main ()
{
Pthread_t thread [3].
Int no=0, res;
Void * thrd_ret;//=malloc (4);
srand(time(NULL));
For (no=0; No{
Res=pthread_create (& amp; Thread [0], NULL, thrd_func, (void *) no);
If (res!=0)
{
Printf (" create % d failed \ n ", no);
The exit (res);
}
}
Printf (" create threads success! \n");

For (no=0; No{
//thrd_ret=(void *) 1;
Res=pthread_join (thread [no], & amp; Thrd_ret);
Printf (" turd_ret ret: % d: % d \ n ", res, (int) thrd_ret);
if(! Res)
{
Printf (" thread % d joined \ n ", no);
}
The else
{
Printf (" thread % d joined failed \ n ", no);
}
}
Run:

Debug:



Ask you the great god see

CodePudding user response:

I found a mistake... Aerobic...
  • Related