[fpc-devel] calls to Fpc-made library from C not thread-safe

Dominique Leducq dleducq at magellan-ing.fr
Thu Nov 30 10:02:43 CET 2006


Hi,

I have a library compiled with Fpc, used from C/C++ programs.
When these C programs call functions of the library from different threads, things break.

As I understand it, the exception stack(s), the standard input/output streams, the threadID and stack checking variables use thread variables, and when the thread is created from C, this variables are not allocated nor initialized.

As a workaround, I thought I could export a function from the library, to be called in each thread before any other library call, which would call CurrentTM.AllocateThreadVars and System.InitThread.
And symetrically, a function to be called after any other library call in the thread, which flushes the input/output streams and calls CurrentTM.ReleaseThreadVars.

Does that sound correct?

Dominique




More information about the fpc-devel mailing list