[fpc-pascal] TThread.Synchronize() in shared library

Michael Van Canneyt michael at freepascal.org
Fri Apr 16 11:40:25 CEST 2010



On Fri, 16 Apr 2010, Matthias Klumpp wrote:

> Hello!
> I have a serious problem with a shared lib and threads.
> To fix a critical bug in my app, the shared library has to execute commands
> asynchronous. To make the non-blocking API I use classes inherited from
> TThread, which process serveral actions. Those threads have to submit data
> back to the main thread of the application. (Status data, messages etc.) I
> use callbacks for this.
> Those callback have to be synced with the main thread of the app which
> makes use of my library. I tried to use Synchronize(), but it did not work.
> (The thread hangs cause Synchronize() can't find the main thread)
> I cannot move the threading part to the main application, it has to be done
> inside of the lib cause of several other reasons.
> Does someone know how I sync with the mainthread of the app which uses my
> lib?
> This would be really great!
> Regards
>   Matthias Klumpp
>
>
>
> P.S: I use FPC 2.4.1 under Linux. If there's a Linux-only solution this
> wouldn't be a problem cause the app will only run on Linux (at time).

Set the thread manager of the library to the main application thread
manager. That should hopefully work. But it is not guaranteed; there
are many issues with libraries and threads under linux.

Michael.



More information about the fpc-pascal mailing list