Library linkage between single threaded and multi threaded (688 Views)
Reply
Advisor
pranav026
Posts: 19
Registered: ‎07-07-2011
Message 1 of 8 (688 Views)

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

Acclaimed Contributor
Dennis Handly
Posts: 25,272
Registered: ‎03-06-2006
Message 2 of 8 (687 Views)

Re: Library linkage between single threaded and multi threaded

[ Edited ]

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.

Advisor
pranav026
Posts: 19
Registered: ‎07-07-2011
Message 3 of 8 (684 Views)

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.

Acclaimed Contributor
Dennis Handly
Posts: 25,272
Registered: ‎03-06-2006
Message 4 of 8 (678 Views)

Re: Library linkage between single threaded and multi threaded

[ Edited ]

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

Advisor
pranav026
Posts: 19
Registered: ‎07-07-2011
Message 5 of 8 (672 Views)

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.


Acclaimed Contributor
Dennis Handly
Posts: 25,272
Registered: ‎03-06-2006
Message 6 of 8 (670 Views)

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.

Advisor
pranav026
Posts: 19
Registered: ‎07-07-2011
Message 7 of 8 (666 Views)

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.

Acclaimed Contributor
Dennis Handly
Posts: 25,272
Registered: ‎03-06-2006
Message 8 of 8 (661 Views)

Re: Library linkage between single threaded and multi threaded

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.