Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2012
    Posts
    1

    questions about pthread


    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?

  2. #2
    Just Joined!
    Join Date
    Jun 2012
    Posts
    3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •