<?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 linking and libc stubs in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/4500765#M638091</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt; When we profiled our application using caliper, we found that a lot&lt;BR /&gt;of time was being spent acquiring locks whenever stl was being used.&lt;BR /&gt;Searching on the internet we found that stl automatically becomes&lt;BR /&gt;thread safe on linking with pthread libraries.&lt;BR /&gt;Our application links with thread safe libraries which are compiled&lt;BR /&gt;with libpthread. One of HP's sites&lt;BR /&gt;(&lt;A href="http://docs.hp.com/en/1896/pthreads.html)" target="_blank"&gt;http://docs.hp.com/en/1896/pthreads.html)&lt;/A&gt; + many articles written by&lt;BR /&gt;HP on libpthread, suggest resolving the pthread lock calls with the&lt;BR /&gt;libc stubs.&lt;BR /&gt;&lt;BR /&gt;So, we did not build our "executable" with "-mt". Hence the load order&lt;BR /&gt;changed, and the calls to the pthread locks were resolved using the&lt;BR /&gt;stubs in libc.&lt;BR /&gt;&lt;BR /&gt;Now, my question is - is this safe ? One of our experts had the following fear&lt;BR /&gt;&lt;BR /&gt;" once we compile part of the code with “-mt” and part without it&lt;BR /&gt;creates a situation of inconsistency as variables for code compiled&lt;BR /&gt;with “-mt” contain additional data structures such as reference count&lt;BR /&gt;and others which is not available for code not compiled with “-mt”."&lt;BR /&gt;&lt;BR /&gt;We link with many third party libraries like oracle client libraries,&lt;BR /&gt;which link with pthread.&lt;BR /&gt;&lt;BR /&gt;Can you please let us know what type of issues can exist with the&lt;BR /&gt;approach we used ? Is it safe ?&lt;BR /&gt;Or can you refer us to some definitive document which will clarify the&lt;BR /&gt;pthread linking issues comprehensively.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt; Sharan Rao</description>
    <pubDate>Mon, 21 Sep 2009 10:52:09 GMT</pubDate>
    <dc:creator>sharanrao</dc:creator>
    <dc:date>2009-09-21T10:52:09Z</dc:date>
    <item>
      <title>Pthread linking and libc stubs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/4500765#M638091</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt; When we profiled our application using caliper, we found that a lot&lt;BR /&gt;of time was being spent acquiring locks whenever stl was being used.&lt;BR /&gt;Searching on the internet we found that stl automatically becomes&lt;BR /&gt;thread safe on linking with pthread libraries.&lt;BR /&gt;Our application links with thread safe libraries which are compiled&lt;BR /&gt;with libpthread. One of HP's sites&lt;BR /&gt;(&lt;A href="http://docs.hp.com/en/1896/pthreads.html)" target="_blank"&gt;http://docs.hp.com/en/1896/pthreads.html)&lt;/A&gt; + many articles written by&lt;BR /&gt;HP on libpthread, suggest resolving the pthread lock calls with the&lt;BR /&gt;libc stubs.&lt;BR /&gt;&lt;BR /&gt;So, we did not build our "executable" with "-mt". Hence the load order&lt;BR /&gt;changed, and the calls to the pthread locks were resolved using the&lt;BR /&gt;stubs in libc.&lt;BR /&gt;&lt;BR /&gt;Now, my question is - is this safe ? One of our experts had the following fear&lt;BR /&gt;&lt;BR /&gt;" once we compile part of the code with “-mt” and part without it&lt;BR /&gt;creates a situation of inconsistency as variables for code compiled&lt;BR /&gt;with “-mt” contain additional data structures such as reference count&lt;BR /&gt;and others which is not available for code not compiled with “-mt”."&lt;BR /&gt;&lt;BR /&gt;We link with many third party libraries like oracle client libraries,&lt;BR /&gt;which link with pthread.&lt;BR /&gt;&lt;BR /&gt;Can you please let us know what type of issues can exist with the&lt;BR /&gt;approach we used ? Is it safe ?&lt;BR /&gt;Or can you refer us to some definitive document which will clarify the&lt;BR /&gt;pthread linking issues comprehensively.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt; Sharan Rao</description>
      <pubDate>Mon, 21 Sep 2009 10:52:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/4500765#M638091</guid>
      <dc:creator>sharanrao</dc:creator>
      <dc:date>2009-09-21T10:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Pthread linking and libc stubs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/4500766#M638092</link>
      <description>Hello Sharan!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Well, I'll try my best to answer your question...&lt;BR /&gt;&lt;BR /&gt;Let's separate your post into three key aspects:&lt;BR /&gt;&lt;BR /&gt;1. Threaded application that uses thread-safe libraries (normal case)&lt;BR /&gt;&lt;BR /&gt;2. Non-threaded application that uses thread-safe libraries (your case)&lt;BR /&gt;&lt;BR /&gt;3. Compilation and linking in threaded applications&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thread safe libraries need symbols from libpthread mainly for synchronization (BUT not exclusively!).&lt;BR /&gt;&lt;BR /&gt;1. When linking threaded applications this synchronization is needed (in app and in libs) and hence libpthread is needed.&lt;BR /&gt;&lt;BR /&gt;2. When linking non-threaded applications this synchronization is not needed (neither in the app nor in the libs, but libs need to resolve their references) and hence HP allows you to link against the dummy pthread* functions in libc (see link you provided). This is a way to speed up execution in libs (thus overall execution of your app).&lt;BR /&gt;&lt;BR /&gt;In case 2. there will be no problems as long as your application does NOT make use of a library that needs pthread* functions for more than synchronization (for example to create threads). This library/ies will have its references resolved with the stub functions in libc too and therefore will stop working correctly.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;3. So now we can compile and link a threaded program:&lt;BR /&gt;&lt;BR /&gt;- using only -mt&lt;BR /&gt;- using only -lpthread&lt;BR /&gt;- using only -lc (dummy pthread functions).&lt;BR /&gt;&lt;BR /&gt;If only using -lc, case 2. applies to your app.&lt;BR /&gt;&lt;BR /&gt;The difference between using -mt COMPILER flag and -lpthread LINKER flag is that the former adds preprocessor defines that are used during compilation (and also the -lpthread flag to the linker), so the safe (and correct) way to compile threaded apps on HP-UX is using -mt!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now back to your case, if you are sure the libs you are linking your non-threaded app to will be happy with the dummy pthread* functions in the libc stub, then no prob. If not or if unsure do not risk, link to libpthread (using -mt ;).&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;&lt;BR /&gt;Kobylka</description>
      <pubDate>Mon, 21 Sep 2009 14:48:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/4500766#M638092</guid>
      <dc:creator>kobylka</dc:creator>
      <dc:date>2009-09-21T14:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Pthread linking and libc stubs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/4500767#M638093</link>
      <description>&amp;gt;is this safe?&lt;BR /&gt;&lt;BR /&gt;Sure, if you don't create threads, there is no need to link with libpthread.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;"once we compile part of the code with "-mt" and part without it creates a situation of inconsistency as variables for code compiled&lt;BR /&gt;with "-mt" contain additional data structures such as reference count and others which is not available for code not compiled with "-mt"."&lt;BR /&gt;&lt;BR /&gt;No, we very cleverly make the structs the exact same size, whether -mt or not.  So this will work, if you don't link with libpthread.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;We link with many third party libraries like oracle client libraries, which link with pthread.&lt;BR /&gt;&lt;BR /&gt;Then you are hosed.  You need to use chatr(1) and LD_LIBRARY_PATH to point to an "empty" shlib named libpthread.so.1.&lt;BR /&gt;&lt;BR /&gt;touch empty.c&lt;BR /&gt;cc -b -o libpthread.so.1 empty.c&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Or can you refer us to some definitive document which will clarify the pthread linking issues comprehensively.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/14487/threads.htm" target="_blank"&gt;http://docs.hp.com/en/14487/threads.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;kobylka: I'll try my best to answer your question.&lt;BR /&gt;&lt;BR /&gt;You did very well.&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Sep 2009 08:07:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/4500767#M638093</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-09-22T08:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Pthread linking and libc stubs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/5661211#M638094</link>
      <description>&lt;P&gt;If my libraries expects linking with libpthread but my end application is not going to run multiple threads, then &amp;nbsp;is there e major performance benefit when comparing linking native libpthread vs empty library ( using stub calls in libc ).??&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2012 20:36:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/5661211#M638094</guid>
      <dc:creator>rApt0r</dc:creator>
      <dc:date>2012-05-17T20:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Pthread linking and libc stubs</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/5661217#M638095</link>
      <description>&lt;P&gt;&amp;gt;If my libraries expects linking with libpthread but my end application is not going to run multiple threads&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your shlibs expect you to link your executable against libpthread, then you should be find if you just use the libc stubs.&amp;nbsp; And you shouldn't have to use that kludge for that empty libpthread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;is there a major performance benefit when comparing linking native libpthread vs empty library??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes.&amp;nbsp; Especially if you don't get a benefit of using multiple threads.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2012 20:48:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pthread-linking-and-libc-stubs/m-p/5661217#M638095</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-05-17T20:48:20Z</dc:date>
    </item>
  </channel>
</rss>

