Threads FAQ

Because I maintain this FAQ with blogging software, the most recently edited item tends to float to the top. If you want to browse a table of contents in “semi-sane” order, here it is.
7 comments on “Threads FAQ
  1. praneeth says:

    hi ,

  2. francisco says:

    how i know if a thread finish?

  3. There’s one special secret Sale link on Amazon:

    This is open every Friday and ONLY on Fridays!

    You can find very good discounts here, although some Fridays you can really get
    lucky and make off like an Amazon bandit – I´ve seen discounts there as low as 75%
    off sticker Price.

  4. Benson says:

    Hey there

    I am new to the subject of thread. Can someone tell me why is the average time that using pthread_create() to creat a thread is shorter than using fork() to create a process?

    My thought is that because parent process has to wait for each child process. On the other hand, thr_create.c includes which only needs to wait for the last thread. Am I correct?

  5. Paul says:

    Hi Benson,

    Threads are faster than a fork() because their overhead is much smaller, as they share the same memory space than their creator. This is why it takes about 30 times less time to create a pthread than fork the current process.

    As for the parent waiting for the children to terminate, it’s up to you. If you create your threads “detached”, they will liberate their own memory space automatically as they terminate. Otherwise, you have to join in order for the threads to return their memory to the heap cleanly.

  6. Steph says:

    Hey i have a question, if i am using pthreads, each of them perform a function, these functions need to be executed in a cylcle…. but the pthread dies everytime the cycle starts, how do i keep my thread alive??

  7. Piyush says:


    I want to execute a thread after some specific time only…lets say 10 to 15 seconds. SLEEP is not workint… it suspends whole program… I want to suspend thread only…

    Is there any way out for that?

    p.s: Time granularity and accuracy doesn’t matters a much.