Thread: pthread create and join problems

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    pthread create and join problems

    i have a daemon process that creates and joins multiple threads.

    every so often the pthread error check will fail and the program terminate.

    under what conditions would the pthread_create function fail?

    i'm really looking for some practical reasons. i believe that the code is correct.

    i'm also having problems with pthread_join hanging randomly.

    any ideas?

    TIA, rotis23

    Code:
    *************************************************
    
            pthread_exit(NULL);     //end of thread_function
    
    *************************************************
    
            int res;
            int lots_of_threads;
            int num_sites;
            pthread_t a_thread[5];
            void *thread_result;
    
            //initialise mutex - used to synchronise linked list between threads
            res = pthread_mutex_init(&queue_mutex, NULL);
            if (res != 0){printf("mutex creation failure.\n");
    
            //add multiple threads
            for(lots_of_threads = 0; lots_of_threads < 5; lots_of_threads++)
            {
                    //threads are created and started
                    res = pthread_create(&(a_thread[lots_of_threads]), NULL,
    thread_function, (void *)lots_of_threads);
                    if (res != 0){printf("create failure.\n");
            }
    
            //wait for threads to finish and clean up
            printf("Waiting for threads to finish...\n");
    
            for(lots_of_threads = 5 - 1; lots_of_threads >= 0;
    lots_of_threads--)
            {
                    res = pthread_join(a_thread[lots_of_threads], NULL);
                    if (res == 0)
                    {
                            printf("Picked up a thread\n");
                    }
                    else{printf("join error.\n");
            }

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    where can i find the error list?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RePhrase: Wanna join a DEV team?
    By Kilo in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-01-2005, 06:42 PM
  2. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM