04-06-2012 10:36 AM
I am trying to write an application on HP UX. I have couple of third party libraries which make use of multi threading. Rest all libraries are single threaded(compiled with no -mt option). Is there any issue if single threaded libraries/application binaries link to multi threaded binaries and vice versa? Do I get any issues during run/compile time? I read some where, that dlopen is not possible from single threaded libs for multi threaded ones.
04-06-2012 10:42 AM - edited 04-06-2012 10:45 AM
If you don't link with libpthread, it doesn't make a difference.
If you do, then every aC++ object must be compiled with -mt.
>that dlopen is not possible from single threaded libs for multi threaded ones.
If your shlib uses TLS, then you would have problems trying to dynamically load it on PA. For Integrity, the default is +tls=dynamic, so it should work fine.
04-06-2012 11:10 AM
Got point to of dlopen, we need to take care of TLS in app we are linking also.
bit confused with linkage between single thareded and multi threaded library, Ok, Assume I have 4 libST1, libST2, libST3 and libMT4, ST stands for single threaded and MT for multi threaded(uses pthreads) and an app binary AppST.sys. Now AppST links to libST1 and libST2, libST3 and libMT4 link to libST2. In this case do I need to build entire app as an Multi threaded, with -mt option? or does it work fine if I build libMT4 with -mt and rest without -mt option.
04-06-2012 12:11 PM - edited 04-06-2012 12:11 PM
>MT for multi threaded (uses pthreads)
Does it really call pthread_create or is just thread safe?
>In this case do I need to build entire app as an Multi threaded
It's pretty simple. If you link with libpthread, EVERYTHING must be compiled with -mt.
(It doesn't matter which load module calls another.)
04-06-2012 11:10 PM
Yes, libMT4, calls pthread_create and implements thread pool.!!
So you want to say entire build chain should be built with -mt, there is no way that we can omit -mt option for libs/app, even they are not making use of pthread_* set of APIs from the linked libMT library.
04-06-2012 11:21 PM
>libMT4, calls pthread_create and implements thread pool.
Unless this is optional, you're hosed.
>So you say entire build chain should be built with -mt, there is no way that we can omit -mt option for libs/app, even they are not making use of pthread_* set of APIs from the linked libMT library.
That's correct. The aC++ runtime for strings and iostream needs to be built consistently with -mt if you link in libpthread.
This code, if not called back from a thread, probably doesn't need to be changed to add locking. Unless their objects being passed to the threads.
04-07-2012 10:20 AM
Thank You Dennis,
cleared my doubts around multithreaded and single threaded library linkage.
One last help, can you point me any relevant docs from HP, which will be good reading around linkers and hp c/c++ compilers.
04-08-2012 12:30 AM
>can you point me any relevant docs from HP, which will be good reading around linkers and HP C/C++ compilers.