Thread: pthread join and cancel

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    1

    pthread join and cancel

    hi,

    if there is three threads a,b,c :
    what happens if thread a cancels thread b ,
    but at the same time b is waiting for join thread c .
    who is responsible for joining c and what happens to b ?


    thnx

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    What do you think happens? Why do you think that? Did you read the documentation (man pages) for pthread_join and pthread_cancel? Have you tried writing a test program to see what happens?

    EDIT: This site is a pretty useful pthreads reference: https://computing.llnl.gov/tutorials/pthreads/.
    Last edited by anduril462; 01-04-2012 at 04:26 PM.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    General Information

    >>who is responsible for joining c
    You are.

    >>... what happens to b ?
    We need actual code to answer these questions.

    gg

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    pthread_join() is a cancellation point. So if thread b is attempting to join thread c, and is cancelled before thread c exits, then the join is aborted and some other thread will have to join thread c. If the thread is not joined its resources will not be released.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cancel socketconnect
    By knutso in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-11-2008, 06:20 AM
  2. cancel a DLL call
    By ryan_germain in forum Windows Programming
    Replies: 10
    Last Post: 08-08-2006, 06:48 AM
  3. Preventing Cancel?
    By JoeCoder in forum Windows Programming
    Replies: 3
    Last Post: 01-18-2004, 03:16 PM
  4. Cancel WaitCommEvent on win2k?
    By yoxler in forum Windows Programming
    Replies: 0
    Last Post: 05-08-2003, 12:34 AM
  5. pthread create and join problems
    By rotis23 in forum C Programming
    Replies: 1
    Last Post: 10-11-2002, 08:41 AM