Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

TThread.Synchronize() in shared library

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matthias Klumpp

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).

Reply by email

Michael Van Canneyt
to Matthias Klumpp
Matthias Klumpp wrote 22 lines
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.

Reply by email

Matthias Klumpp
to Michael Van Canneyt
Show quoted text 5 lines
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.

How do I do that?
(There is also another thing which I have forgotten: The library should be compatible with applications written in C...)

Matthias

Reply by email

Michael Van Canneyt
to Matthias Klumpp
Matthias Klumpp wrote 6 lines
> 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. How do I do that?

Export SetThreadManager() and call it from your main application with the threadmanager from the main application.

(There is also another thing which I have forgotten: The library should be compatible with applications written in C...)

In that case: forget it; this is currently not possible. Too many problems.

Michael.

Reply by email

Matthias Klumpp
to Michael Van Canneyt

Thank you for your help!
I will now move some parts of the lib to a DBus daemon and run only the necessary parts of the lib in extra threads.
I'll also try to set the threadmanager.

Michael Van Canneyt wrote 17 lines
On Fri, 16 Apr 2010, Matthias Klumpp wrote: >> 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. > How do I do that? Export SetThreadManager() and call it from your main application with the threadmanager from the main application. > (There is also another thing which I have forgotten: The library should > be > compatible with applications written in C...) In that case: forget it; this is currently not possible. Too many

problems.

Show quoted text 5 lines
Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email