Operating System - HP-UX
1745821 Members
3881 Online
108722 Solutions
New Discussion

Re: Library linkage between single threaded and multi threaded

 
pranav026
Advisor

Library linkage between single threaded and multi threaded

 

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.

 

Thank You

7 REPLIES 7
Dennis Handly
Acclaimed Contributor

Re: Library linkage between single threaded and multi threaded

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.

pranav026
Advisor

Re: Library linkage between single threaded and multi threaded

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.

Dennis Handly
Acclaimed Contributor

Re: Library linkage between single threaded and multi threaded

>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.)

pranav026
Advisor

Re: Library linkage between single threaded and multi threaded

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.


Dennis Handly
Acclaimed Contributor

Re: Library linkage between single threaded and multi threaded

>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.

pranav026
Advisor

Re: Library linkage between single threaded and multi threaded

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.

Dennis Handly
Acclaimed Contributor

Re: Library linkage between single threaded and multi threaded