Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 940275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:55:43+00:00 2026-05-15T21:55:43+00:00

am trying to get my head around the following: Have a small program am

  • 0

am trying to get my head around the following:

Have a small program am trying to port to OSX(intel) which calls function doWork()
via pthread_create, in the function, I start by creating an array of long like such:

long myarray[DIMENSION]

on OSX, for the following values of DIMENSION, I get the following:

0->65434 = fine
65435->67037 = SIGBUS
67037+ = SIGSEGV

I’m totally confused here, I understand that SIGBUS is due to memory alignment issues usually, I checked sizeof(long) and it appears to be 8 on this platform. Can somebody point me in the right direction of docs I should be reading here?

Here is the source:


#include pthread.h
#include stdio.h
#define NUM_THREADS     5
#define DIMENSION       12345

void *doStuff(void *threadid)
{
   long array[DIMENSION];
   pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   for(t=0; t lt NUM_THREADS; t++){
      printf("In main: creating thread %ld\n", t);
      rc = pthread_create(&threads[t], NULL, doStuff, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   pthread_exit(NULL);
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:55:43+00:00Added an answer on May 15, 2026 at 9:55 pm

    It would appear you’re overflowing the stack.

    You’ll need to either turn the long array into a malloced one, or use pthread_attr_setstacksize and friends to create a larger stack when you call pthread_create.

    Default thread stack sizes vary a lot between platforms, which would explain why the code works on other platforms.

    Example code:

       pthread_attr_t attr;
       size_t stacksize;
    
       pthread_attr_init(&attr);
       pthread_attr_getstacksize(&attr, &stacksize);
       printf("Default stack size = %li\n", stacksize);
       stacksize = <....>;
       printf("Amount of stack needed per thread = %li\n",stacksize);
       pthread_attr_setstacksize(&attr, stacksize);
       rc = pthread_create(&thread, &attr, dowork, (void *)t);
    

    (code originally from https://github.com/LLNL/HPC-Tutorials/blob/main/posix/stack_management.md )

    As to why you get a sigbus, it’s probably because the act of creating the array is overwriting some part of pthreads internal data structures with garbage, resulting in an alignment error when pthreads tries to clean up the thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to get my head around jQuery's Ajax. I have a page
I'm trying to get my head around another issue i'm facing with my multi-tenant
I'm still trying to get my head around mocking. Right now, I'm trying to
I'm having problems trying to get my head around getting a collection of types
I'm new to JSON & am having a hard time trying to get my
Hi i have a partial website up as im having extreme difficultys trying to
So I am in the process of trying to learn how to develop 2D
I`m a JavaScript/programming newbie trying to figure out the new bookmarklet that's been released
I'm having an issue where I need to get the sum of a group
I've read through the source code but it seems a little cryptic. I'm just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.