Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack size in Unix pthread_create

Tags:

pthreads

I am creating 10 threads using pthread_create in my application. What is the default stack size assigned to each thread?

I am trying to debug a crash where my application is crashing on an illegal instruction where one of the function pointer is reset to 0. One of the indicator of this can be my application thread has run out of stack size and it overwrote an existing stack space where the function pointer was residing.

like image 802
user1255206 Avatar asked Mar 18 '26 18:03

user1255206


1 Answers

See https://computing.llnl.gov/tutorials/pthreads/ for a tutorial on pthreads. You set the initial stack size with the attr parameter, created with pthread_attr_init. In general, though, you do not want to have a huge stack. If you are allocating more than a few hundred kilobytes on the stack, you may find it easier to debug your program by allocating the data on the heap and freeing it as needed.

like image 167
vy32 Avatar answered Mar 23 '26 10:03

vy32



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!