Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2013-05

LoadLibrary result

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

I'm using a list of objects that each needs to load a shared Library (written in C). As some operations inside the library are slow, I've created a TThread to do multiple operations simultaneously.

As the library is not thread safe, I thought using "loadLibrary" will create a different "instance" after each load, but, as the TLibHandle resulting of that function is the same, I think the library is only loaded once.

Is there a way to have different handles for each loadlibrary?.

 
Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Jonas Maebe
to Leonardo M. Ramé
Leonardo M. Ramé wrote 5 lines
I'm using a list of objects that each needs to load a shared Library (written in C). As some operations inside the library are slow, I've created a TThread to do multiple operations simultaneously. As the library is not thread safe, I thought using "loadLibrary" will create a different "instance" after each load, but, as the TLibHandle resulting of that function is the same, I think the library is only loaded once. Is there a way to have different handles for each loadlibrary?.

No, you can load a library only once per process. Loading it more than once is not supported by any dynamic linker I know of, because it would result in symbol clashes.

Jonas

Reply by email

Leonardo M. Ramé
to Jonas Maebe
Show quoted text 19 lines
________________________________ From: Jonas Maebe To: Leonardo M. Ramé ; FPC developers' list Sent: Thursday, May 30, 2013 12:40 PM Subject: Re: [fpc-devel] LoadLibrary result On 30 May 2013, at 17:27, Leonardo M. Ramé wrote: > I'm using a list of objects that each needs to load a shared Library (written in C). As some operations inside the library are slow, I've created a TThread to do multiple operations simultaneously. > > As the library is not thread safe, I thought using "loadLibrary" will create a different "instance" after each load, but, as the TLibHandle resulting of that function is the same, I think the library is only loaded once. > > Is there a way to have different handles for each loadlibrary?. No, you can load a library only once per process. Loading it more than once is not supported by any dynamic linker I know of, because it would result in symbol clashes.

Thanks Jonas, good to know that.

I'll have to re-architect the library to avoid using globals...

Reply by email