
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Get and Set the stack size of thread attribute in C
To get and set the stack size of thread attribute in C, we use the following thread attributes:
pthread_attr_getstacksize()
Use for get threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. In case of a successful run, then it gives 0 otherwise gives any value.
It takes two arguments −
pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)
- First one for pthread attribute.
- Second one for giving the size of the thread attribute.
pthread_attr_setstacksize()
Used for set new threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. In case of a successful run, then it gives 0 otherwise it gives any value.
It takes two arguments −
pthread_attr_setstacksize(pthread_attr_t *attr, size_t *stacksize)
- First one for pthread attribute.
- Second one for give the size of the new stack in bytes.
Algorithm
Begin Declare stack size and declare pthread attribute a. Gets the current stacksize by pthread_attr_getstacksize() and print it. Set the new stack size by pthread_attr_setstacksize() and get the stack size pthread_attr_getstacksize() and print it. End
Example Code
#include <stdio.h> #include <stdlib.h> #include <pthread.h> int main() { size_t stacksize; pthread_attr_t a; pthread_attr_getstacksize(&a, &stacksize); printf("Current stack size = %d
", stacksize); pthread_attr_setstacksize(&a, 67626); pthread_attr_getstacksize(&a, &stacksize); printf("New stack size= %d
", stacksize); return 0; }
Output
Current stack size = 50 New stack size= 67626
- Related Articles
- stack empty() and stack size() in C++ STL
- How to get stack trace using thread in Java 9?
- How to get the thread ID from a thread in C#?
- Swift program to Get the Size of Set
- Get object at the top of the Stack in C#
- Get the number of elements contained in the Stack in C#
- How to display all stack frames of the current thread in Java 9?
- HTML size Attribute
- HTML size Attribute
- HTML size Attribute
- How to get Synchronize access to the Stack in C#?
- Get current thread in Java
- Python program to get all subsets of given size of a set
- Set the size of the icons in HTML
- Role of size property in CSS to set the size and orientation of a page box

Advertisements