[Lazarus] Threads and Libraries (dll and so)

Michael Van Canneyt michael at freepascal.org
Fri Jan 17 12:53:33 CET 2014

On Fri, 17 Jan 2014, Antonio Fortuny wrote:

> Hi All.
> Maybe not a Lazarus/FPC specific question but development whill be done using 
> Lazarus/FPC.
> I wonder if I can build an application (service) having multiple threads 
> running (Indy TCP/IP server, multiple connections) and every thread calls 
> some functions in a library (dll on Windows, .so on Linux)
> I can imagine that if every thread loads dynamically the library it should 
> work as I assume that a library shares its code among all callers (processes 
> ?) but each instance has its own data segment tied tp the calling process 
> (thread ?).

The data segment is tied to the process, not to the thread.

So global variables in the DLL are shared by all threads of the calling process.
If you define threadvars in the DLL, they will normally be specific to threads 
of the calling program (just as they would be if the library created the thread).


More information about the Lazarus mailing list