develooper Front page | perl.perl5.porters | Postings from March 2006

pthread_attr_setstacksize failure

From:
Jerry D. Hedden
Date:
March 25, 2006 15:32
Subject:
pthread_attr_setstacksize failure
Message ID:
20060325163230.fb30e530d17747c2b054d625b8945d88.def13aacac.wbe@email.email.secureserver.net
I have received a couple of failure reports against the threads module
related to the new threads stack size API.  A recent failure report had
the following error message:

    Thread creation failed: pthread_attr_setstacksize(2097152) returned
22

This shows that the pthread_attr_setstacksize function was called with
the stack size of 2MB (exactly), and that the function returned EINVAL.

If you get the source code for the pthread_attr_setstacksize function,
you find that the only cause for this error code is too small of a
stack size:

  /* Catch invalid sizes.  */
  if (stacksize < PTHREAD_STACK_MIN)
    return EINVAL;

Usually that minimum is 16K, however, the threads module code checks
against whatever PTHREAD_STACK_MIN is set to, so 2MB should be valid.

Within the threads module code, stack size is carried as an IV:

    typedef struct ithread_s {
        ...
        IV stack_size;
    } ithread;    IV stack_size;

And the call to pthread_attr_setstacksize casts it to size_t:

    #  ifdef _POSIX_THREAD_ATTR_STACKSIZE
        /* Set thread's stack size */
        if (thread->stack_size > 0) {
            rc_stack_size = pthread_attr_setstacksize(&attr,
(size_t)thread->stack_size);
        }
    #  endif

Is it possible that the compiler is not performing the conversion of the
64-bit int (IV) to a 32-bit int (persumably what size_t is)?  Other than
that, I can think of no reason why the above error would occur.

The two reports both came from Linux machines:

    debian 3.1 stable
    linux lappy 2.4.22 (Perl 5.8.7 with use64bitint=define)

Does anyone have any idea what I might be missing?




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About