I used the pthread_create function to create a new thread,
why this new thread can not run until I use phread_join to wait it
exit?
If I not use pthread_join , only the main thread is running.I want to
ask what is the new thread doing?
Printable View
I used the pthread_create function to create a new thread,
why this new thread can not run until I use phread_join to wait it
exit?
If I not use pthread_join , only the main thread is running.I want to
ask what is the new thread doing?
Once you use pthread_create - thread will be created and time slice will be given to it immediately. And we cannot say which thread will excute first.
When you use pthread_join - parent thread waits for the child thread to complete. Then you can see the child execution. But without this, parent thread might exit before the child thread completes its execution.
Try using wait, sleep in the child thread and also parent thread - use printf before and after the waiting functions - then you can see the real flow of execution