[fpc-devel] calls to Fpc-made library from C not thread-safe
vlad_mail_ru at mail.ru
Thu Nov 30 15:43:28 CET 2006
> 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?
I'm in similar situation under Mac OS X.
I have to create dummy thread when library loaded and then to use such functions in additional threads:
InitThread(500000); // 500000 is the stack size, all threads have 512Kb stack, not sure must here be exact stack size or not.
More information about the fpc-devel