pthread_create returns error code 11

Discussion in 'C++' started by Joy, May 27, 2009.

  1. Joy

    Joy Guest

    i have a code that uses pthread, but when i use pthread_create()
    method it returns error code 11. I have found out that this is often
    because of exceeding the THREAD_MAX limit for the process. But i want
    to use only about 24 threads at a given time, and i destroy the
    threads (or atleast i thought so) can someone tell me what i am doing
    wrong here it would be of great help! thanks!

    for (i=0; i<no_pairs; ){
    for (j=0; j<MAX_THREADS && i<no_pairs; j++,i++){
    data[j].a = seeds[i/no_seeds];
    data[j].b = seeds[i%no_seeds];
    data[j].N = N;
    data[j].L = nones+nzeros;
    data[j].p1 = get_string (seeds[i/no_seeds], nzeros
    +nones-1);
    data[j].p2 = get_string (seeds[i%no_seeds], nzeros
    +nones-1);
    data[j].results = pairs;
    rc = pthread_create (&threads[j], &attr, run_actree, (void
    *)
    &data[j]);
    if (rc) {
    printf ("ERROR; return code from pthread_create() is %d
    \n", rc);
    exit (-1);
    }
    }
    for (k=0; k<j; k++){
    rc = pthread_join (threads[k], &status);
    if (rc) {
    printf("ERROR; return code from pthread_join() is %d
    \n", rc);
    exit(-1);
    }
    }
    }

    pthread_attr_destroy (&attr);

    Above is the main loop i create threads in, MAX_THREADS = 24

    Any help as to where i am going wrong is greatly appreciated.
    Joy, May 27, 2009
    #1
    1. Advertising

  2. Joy wrote:

    > i have a code that uses pthread, but when i use pthread_create()
    > method it returns error code 11. I have found out that this is often
    > because of exceeding the THREAD_MAX limit for the process. But i want
    > to use only about 24 threads at a given time, and i destroy the
    > threads (or atleast i thought so) can someone tell me what i am doing
    > wrong here it would be of great help! thanks!


    First off, 24 threads sounds like an awful lot to me.
    Is there any particular reason you need so many? Because unless you are
    working on a serious multi-processor/multi-core machine, there is no way
    that this many threads is going to buy you anything in processor
    utilisation.

    >
    > for (i=0; i<no_pairs; ){
    > for (j=0; j<MAX_THREADS && i<no_pairs; j++,i++){
    > data[j].a = seeds[i/no_seeds];
    > data[j].b = seeds[i%no_seeds];
    > data[j].N = N;
    > data[j].L = nones+nzeros;
    > data[j].p1 = get_string (seeds[i/no_seeds], nzeros
    > +nones-1);
    > data[j].p2 = get_string (seeds[i%no_seeds], nzeros
    > +nones-1);
    > data[j].results = pairs;
    > rc = pthread_create (&threads[j], &attr, run_actree, (void
    > *)
    > &data[j]);
    > if (rc) {
    > printf ("ERROR; return code from pthread_create() is
    > %d
    > \n", rc);


    It might be helpful in understanding when the error occurs to print i
    and j as well.

    > exit (-1);
    > }
    > }
    > for (k=0; k<j; k++){
    > rc = pthread_join (threads[k], &status);
    > if (rc) {
    > printf("ERROR; return code from pthread_join() is %d
    > \n", rc);
    > exit(-1);
    > }
    > }
    > }
    >
    > pthread_attr_destroy (&attr);
    >
    > Above is the main loop i create threads in, MAX_THREADS = 24
    >
    > Any help as to where i am going wrong is greatly appreciated.


    My guess is that the value of MAX_THREADS also includes the thread that
    is spawning all the others. If that is so, the failure will occur at
    j==23.

    Bart v Ingen Schenau
    --
    a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
    c.l.c FAQ: http://c-faq.com/
    c.l.c++ FAQ: http://www.parashift.com/c -faq-lite/
    Bart van Ingen Schenau, May 27, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vertigo

    pthread_create for class ?

    vertigo, Aug 28, 2004, in forum: Java
    Replies:
    4
    Views:
    969
    Tor Iver Wilhelmsen
    Aug 29, 2004
  2. nightowl
    Replies:
    1
    Views:
    2,167
    Ron Natalie
    Oct 21, 2004
  3. Gary Wessle

    pthread_create error

    Gary Wessle, Oct 21, 2006, in forum: C++
    Replies:
    9
    Views:
    1,027
    Larry Smith
    Oct 21, 2006
  4. Keith Thompson

    Re: pthread_create returns error code 11

    Keith Thompson, May 27, 2009, in forum: C Programming
    Replies:
    10
    Views:
    936
    Chris M. Thomasson
    May 31, 2009
  5. Drew Lawson

    Re: pthread_create returns error code 11

    Drew Lawson, May 27, 2009, in forum: C Programming
    Replies:
    1
    Views:
    7,327
    Antoninus Twink
    May 28, 2009
Loading...

Share This Page