[fpc-pascal] Shared libraries and threadvars

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Tue Jun 26 14:01:41 CEST 2012


I'm currently tinkering with shared libraries, using cmem, mainly on 
Linux. In one case the main-program code is multithreaded, but so far 
I'm not moving data between threads inside the library.

Am I correct in believing that unit-level variables in a shared library 
might end up being shared between multiple instances of the library, or 
are they guaranteed to be distinct?

If my belief is correct, I presume that I could get around this by using 
threadvars. But in this case, how would I best implement a variable that 
I wanted to be common across related threads (e.g. to track the number 
of a particular object being allocated/deallocated), but distinct across 
program invocations (i.e. two programs using the same shared library 
wouldn't clash)?

The discussion of libraries in ch16 of the Language reference guide is 
rather quiet on the semantics.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list