- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- PTHREAD stack size
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 08:42 PM
03-13-2023 08:42 PM
Hi ,
I have written the setting the size code foe less than the PTHREAD_STACK_MIN and greater than PTHREAD_STACK_MIN, I want to write the if our local stack size is equal to PTHREAD_STACK_MIN, but I had stuck here , can you please help me on how to write the logic for last condition
s = pthread_attr_init(&attr);
if (s != 0) {
FYI(FYI_FATAL, "%s pthread_attr_init failed %ld\n",__FUNCTION__,s);
}
if (StackSize < PTHREAD_STACK_MIN) {
FYI(FYI_INFORM, "Stack size is less than PTHREAD_STACK_MIN, hardcoding to PTHREAD_STACK_MIN\n" );
StackSize = PTHREAD_STACK_MIN;
} else if (StackSize > PTHREAD_STACK_MIN) {
s = pthread_attr_setstacksize(&attr, StackSize);
if (s != 0) {
FYI(FYI_FATAL, "%s pthread_attr_setstacksize failed %ld\n", __FUNCTION__, s);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 02:24 AM
03-21-2023 02:24 AM
Re: PTHREAD stack size
Hello @meghana9490
To handle the case where the local stack size is equal to PTHREAD_STACK_MIN, you can add an extra condition in your code to check if StackSize is equal to PTHREAD_STACK_MIN. If it is, you can simply skip the call to pthread_attr_setstacksize() and use the default stack size provided by the system.
Here's how you can modify your code to handle this case:
s = pthread_attr_init(&attr);
if (s != 0) {
FYI(FYI_FATAL, "%s pthread_attr_init failed %ld\n", __FUNCTION__, s);
}
if (StackSize < PTHREAD_STACK_MIN) {
FYI(FYI_INFORM, "Stack size is less than PTHREAD_STACK_MIN, hardcoding to PTHREAD_STACK_MIN\n" );
StackSize = PTHREAD_STACK_MIN;
} else if (StackSize > PTHREAD_STACK_MIN) {
s = pthread_attr_setstacksize(&attr, StackSize);
if (s != 0) {
FYI(FYI_FATAL, "%s pthread_attr_setstacksize failed %ld\n", __FUNCTION__, s);
}
} else {
// StackSize is equal to PTHREAD_STACK_MIN, use default stack size
FYI(FYI_INFORM, "Stack size is equal to PTHREAD_STACK_MIN, using default stack size\n");
}
In this modified code, the 'else' block handles the case where StackSize is equal to PTHREAD_STACK_MIN. You can add any additional logic or print statements inside this block as per your requirement.
NOTE: Am not an expert, I may go wrong. Take a back-up of the data, before you perform any steps. You can give a try on your own risk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 06:46 AM - edited 03-21-2023 06:47 AM
03-21-2023 06:46 AM - edited 03-21-2023 06:47 AM
Re: PTHREAD stack size
Hi @Vinky_99
I have changed as you said, can you please look into this
s = pthread_attr_init(&attr);
if (s != 0) {
FYI(FYI_FATAL, "%s pthread_attr_init failed %ld\n",__FUNCTION__,s);
exit(1);
}
if (pthread_attr_getstacksize(&attr, &StackSize) != 0) {
StackSize = PTHREAD_STACK_MIN;
}
/* Check if the stacksize is large enough */
if (StackSize < PTHREAD_STACK_MIN) {
FYI(FYI_INFORM, "Stack size is less than PTHREAD_STACK_MIN, hardcoding to PTHREAD_STACK_MIN\n" );
StackSize = PTHREAD_STACK_MIN;
s = pthread_attr_setstacksize(&attr, StackSize);
}
/* Set stacksize and try to reinitialize attr if failed */
if (StackSize >= PTHREAD_STACK_MIN && pthread_attr_setstacksize(&attr, StackSize) != 0 && pthread_attr_init(&attr)) {
FYI(FYI_INFORM, "can't set log thread stack size\n");
exit(1);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 11:17 PM
03-22-2023 11:17 PM
SolutionOn the modified code you provided, you have added an additional check to retrieve the current stack size using pthread_attr_getstacksize() function before setting the stack size. This is a good practice to ensure that you are working with a valid stack size.
The code also handles the case where the requested stack size is less than PTHREAD_STACK_MIN by hardcoding it to PTHREAD_STACK_MIN and setting the stack size using pthread_attr_setstacksize().
In the else block, you are attempting to set the stack size using pthread_attr_setstacksize() and then reinitializing the attribute using pthread_attr_init() if it fails. However, the check condition is incorrect, as pthread_attr_init() returns 0 on success and non-zero on error. So, you should use if (StackSize >= PTHREAD_STACK_MIN && pthread_attr_setstacksize(&attr, StackSize) != 0 && pthread_attr_init(&attr) != 0) instead.
Overall, the modified code looks good and should work as intended.
Good Luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 12:24 AM
03-24-2023 12:24 AM
Re: PTHREAD stack size
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2023 08:27 AM
03-24-2023 08:27 AM