<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic PTHREAD stack size in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7184549#M495960</link>
    <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written the setting the size code foe less than the&amp;nbsp;PTHREAD_STACK_MIN and greater than&amp;nbsp;PTHREAD_STACK_MIN, I want to write the if our local stack size is equal to&amp;nbsp;PTHREAD_STACK_MIN, but I had stuck here , can you please help me on how to write the logic for last condition&lt;/P&gt;&lt;P&gt;s = pthread_attr_init(&amp;amp;attr);&lt;BR /&gt;if (s != 0) {&lt;BR /&gt;FYI(FYI_FATAL, "%s pthread_attr_init failed %ld\n",__FUNCTION__,s);&lt;BR /&gt;}&lt;BR /&gt;if (StackSize &amp;lt; PTHREAD_STACK_MIN) {&lt;BR /&gt;FYI(FYI_INFORM, "Stack size is less than PTHREAD_STACK_MIN, hardcoding to PTHREAD_STACK_MIN\n" );&lt;BR /&gt;StackSize = PTHREAD_STACK_MIN;&lt;BR /&gt;} else if (StackSize &amp;gt; PTHREAD_STACK_MIN) {&lt;BR /&gt;s = pthread_attr_setstacksize(&amp;amp;attr, StackSize);&lt;BR /&gt;if (s != 0) {&lt;BR /&gt;FYI(FYI_FATAL, "%s pthread_attr_setstacksize failed %ld\n", __FUNCTION__, s);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 03:42:16 GMT</pubDate>
    <dc:creator>meghana9490</dc:creator>
    <dc:date>2023-03-14T03:42:16Z</dc:date>
    <item>
      <title>PTHREAD stack size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7184549#M495960</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written the setting the size code foe less than the&amp;nbsp;PTHREAD_STACK_MIN and greater than&amp;nbsp;PTHREAD_STACK_MIN, I want to write the if our local stack size is equal to&amp;nbsp;PTHREAD_STACK_MIN, but I had stuck here , can you please help me on how to write the logic for last condition&lt;/P&gt;&lt;P&gt;s = pthread_attr_init(&amp;amp;attr);&lt;BR /&gt;if (s != 0) {&lt;BR /&gt;FYI(FYI_FATAL, "%s pthread_attr_init failed %ld\n",__FUNCTION__,s);&lt;BR /&gt;}&lt;BR /&gt;if (StackSize &amp;lt; PTHREAD_STACK_MIN) {&lt;BR /&gt;FYI(FYI_INFORM, "Stack size is less than PTHREAD_STACK_MIN, hardcoding to PTHREAD_STACK_MIN\n" );&lt;BR /&gt;StackSize = PTHREAD_STACK_MIN;&lt;BR /&gt;} else if (StackSize &amp;gt; PTHREAD_STACK_MIN) {&lt;BR /&gt;s = pthread_attr_setstacksize(&amp;amp;attr, StackSize);&lt;BR /&gt;if (s != 0) {&lt;BR /&gt;FYI(FYI_FATAL, "%s pthread_attr_setstacksize failed %ld\n", __FUNCTION__, s);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 03:42:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7184549#M495960</guid>
      <dc:creator>meghana9490</dc:creator>
      <dc:date>2023-03-14T03:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: PTHREAD stack size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7184914#M495961</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/2125124"&gt;@meghana9490&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here's how you can modify your code to handle this case:&lt;/P&gt;&lt;P&gt;s = pthread_attr_init(&amp;amp;attr);&lt;BR /&gt;if (s != 0) {&lt;BR /&gt;FYI(FYI_FATAL, "%s pthread_attr_init failed %ld\n", __FUNCTION__, s);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (StackSize &amp;lt; PTHREAD_STACK_MIN) {&lt;BR /&gt;FYI(FYI_INFORM, "Stack size is less than PTHREAD_STACK_MIN, hardcoding to PTHREAD_STACK_MIN\n" );&lt;BR /&gt;StackSize = PTHREAD_STACK_MIN;&lt;BR /&gt;} else if (StackSize &amp;gt; PTHREAD_STACK_MIN) {&lt;BR /&gt;s = pthread_attr_setstacksize(&amp;amp;attr, StackSize);&lt;BR /&gt;if (s != 0) {&lt;BR /&gt;FYI(FYI_FATAL, "%s pthread_attr_setstacksize failed %ld\n", __FUNCTION__, s);&lt;BR /&gt;}&lt;BR /&gt;} else {&lt;BR /&gt;// StackSize is equal to PTHREAD_STACK_MIN, use default stack size&lt;BR /&gt;FYI(FYI_INFORM, "Stack size is equal to PTHREAD_STACK_MIN, using default stack size\n");&lt;BR /&gt;}&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt; 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.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 09:24:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7184914#M495961</guid>
      <dc:creator>Vinky_99</dc:creator>
      <dc:date>2023-03-21T09:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: PTHREAD stack size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7184924#M495962</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/2109495"&gt;@Vinky_99&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have changed as you said, can you please look into this&lt;/P&gt;&lt;P&gt;s = pthread_attr_init(&amp;amp;attr);&lt;BR /&gt;if (s != 0) {&lt;BR /&gt;FYI(FYI_FATAL, "%s pthread_attr_init failed %ld\n",__FUNCTION__,s);&lt;BR /&gt;exit(1);&lt;BR /&gt;}&lt;BR /&gt;if (pthread_attr_getstacksize(&amp;amp;attr, &amp;amp;StackSize) != 0) {&lt;BR /&gt;StackSize = PTHREAD_STACK_MIN;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/* Check if the stacksize is large enough */&lt;BR /&gt;if (StackSize &amp;lt; PTHREAD_STACK_MIN) {&lt;BR /&gt;FYI(FYI_INFORM, "Stack size is less than PTHREAD_STACK_MIN, hardcoding to PTHREAD_STACK_MIN\n" );&lt;BR /&gt;StackSize = PTHREAD_STACK_MIN;&lt;BR /&gt;s = pthread_attr_setstacksize(&amp;amp;attr, StackSize);&lt;BR /&gt;}&lt;BR /&gt;/* Set stacksize and try to reinitialize attr if failed */&lt;BR /&gt;if (StackSize &amp;gt;= PTHREAD_STACK_MIN &amp;amp;&amp;amp; pthread_attr_setstacksize(&amp;amp;attr, StackSize) != 0 &amp;amp;&amp;amp; pthread_attr_init(&amp;amp;attr)) {&lt;BR /&gt;FYI(FYI_INFORM, "can't set log thread stack size\n");&lt;BR /&gt;exit(1);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 13:47:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7184924#M495962</guid>
      <dc:creator>meghana9490</dc:creator>
      <dc:date>2023-03-21T13:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: PTHREAD stack size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7185007#M495963</link>
      <description>&lt;P&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/2125124"&gt;@meghana9490&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the modified code you provided,&amp;nbsp;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.&lt;/P&gt;&lt;P&gt;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().&lt;/P&gt;&lt;P&gt;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 &amp;gt;= PTHREAD_STACK_MIN &amp;amp;&amp;amp; pthread_attr_setstacksize(&amp;amp;attr, StackSize) != 0 &amp;amp;&amp;amp; pthread_attr_init(&amp;amp;attr) != 0) instead.&lt;/P&gt;&lt;P&gt;Overall, the modified code looks good and should work as intended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good Luck!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 06:17:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7185007#M495963</guid>
      <dc:creator>Vinky_99</dc:creator>
      <dc:date>2023-03-23T06:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: PTHREAD stack size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7185102#M495964</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/2109495"&gt;@Vinky_99&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your solution&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 07:24:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7185102#M495964</guid>
      <dc:creator>meghana9490</dc:creator>
      <dc:date>2023-03-24T07:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: PTHREAD stack size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7185147#M495965</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/2125124"&gt;@meghana9490&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's great!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We are glad to know your concern has been addressed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 15:27:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-stack-size/m-p/7185147#M495965</guid>
      <dc:creator>Sunitha_Mod</dc:creator>
      <dc:date>2023-03-24T15:27:07Z</dc:date>
    </item>
  </channel>
</rss>

