Find the answer to your Linux question:
Results 1 to 2 of 2
I am working with the Perl's threads module, adding a new API for controlling thread stack size. I have received a couple of failure reports with the following error message: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2006
    Posts
    1

    Thread stack size failure


    I am working with the Perl's threads module, adding a new API for controlling thread stack size. I have received a couple of failure reports with the following error message:

    Thread creation failed: pthread_attr_setstacksize(2097152) returned 22

    (Note: This is descriptive - the actual function call is below). 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 (64-bit int):

    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?

  2. #2
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401
    Here is the implementation on pthread_attr_setstacksize on my system (Debian testing):

    Code:
    int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
    {
    #ifdef FLOATING_STACKS
      /* We have to check against the maximum allowed stack size.  This is no
         problem if the manager is already started and we determined it.  If
         this hasn't happened, we have to find the limit outself.  */
      if (__pthread_max_stacksize == 0)
        __pthread_init_max_stacksize ();
    
      if (stacksize > __pthread_max_stacksize)
        return EINVAL;
    #else
      /* We have a fixed size limit.  */
      if (stacksize > STACK_SIZE)
        return EINVAL;
    #endif
    
      /* We don't accept value smaller than PTHREAD_STACK_MIN.  */
      if (stacksize < PTHREAD_STACK_MIN)
        return EINVAL;
    
      attr->__stacksize = stacksize;
      return 0;
    }
    You can notice the check stacksize > STACK_SIZE... probably this cause an error...

    Sources are glibc-2.3.6.
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •