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 7948061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:36:47+00:00 2026-06-04T01:36:47+00:00

I have written a small program to create thread and change their default stack

  • 0

I have written a small program to create thread and change their default stack size but in my case . When i am printing the stacksize after changing the attribute, i am still getting stacksize displayed as default stack size .

        # include<iostream>
        # include<pthread.h>
        # include<stdio.h>
        # define size 10
        using namespace std;
        pthread_attr_t attr;

        void* sum(void * threadid)
        {
          static int sum =0;
          sum=sum+5;
          long id=(long)threadid;
          size_t mystacksize;
          pthread_attr_getstacksize(&attr,&mystacksize);
          cout << " stack size  "<< mystacksize <<endl;
        }
        int main()
        {
         int rc;
         long t=0;
         pthread_t threads[5];  //number of different thread to br creatd
         size_t stacksize;
         pthread_attr_init(&attr);
         pthread_attr_getstacksize(&attr,&stacksize);   //gets the default stack size 
                                                        //allocated for thread
         cout <<" Default stack size is : " << stacksize <<endl; 
         stacksize=size;
         pthread_attr_setstacksize(&attr,stacksize);  //sets a new stacksize for thread
           for(t=0;t<5;t++)
            {
              rc=pthread_create(&threads[t],&attr,sum,(void*)t);
              if(rc)
              cout << "thread creation failed with id : " << t <<endl;
            }
         pthread_exit(NULL);
        return 0;
        }

output is :-

           Default stack size is : 8388608
           stack size  : 8388608
           stack size  : 8388608
           stack size  : 8388608
           stack size  : 8388608
           stack size  : 8388608

Also note that if i try and increase the stacksize greater than default size i am successfully able to do so .

  • 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-06-04T01:36:49+00:00Added an answer on June 4, 2026 at 1:36 am

    It’s crazy to expect to be able to use a stack size of ten bytes.

    Did you read the pthread_attr_setstacksize man page? Did you check the return value of calling pthread_attr_setstacksize?

    On my system (GNU/Linux) the man page says:

       pthread_attr_setstacksize() can fail with the following error:
    
       EINVAL The stack size is less than PTHREAD_STACK_MIN (16384) bytes.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small plugin to change the text size but it doesn't
I have written a small example C++ program, using boost::thread. Since it's 215 lines,
I have visual studio 2008. I have a written a small C program. I
I have written a small function, which uses ElementTree to parse xml file,but it
I have written a small program using Borland's C++ builder, and along the way,
I have written a small program , to understand how futures work in c++0x.
I have written a small program and compiled it under Solaris/Linux platform to measure
Let say I have written a small program that reads file_A and file_B as
I have written a very small C# program, that uses a very small SQL
I have written a small program displaying sounds and images on the screen when

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.