[Lazarus] Threads and Libraries (dll and so)

Michael Schnell mschnell at lumino.de
Mon Jan 20 14:46:27 CET 2014

On 01/20/2014 11:01 AM, Michael Van Canneyt wrote:
> http://qt-project.org/doc/qt-4.8/threads-starting.html
> "Note that QCoreApplication::exec() must always be called from the 
> main thread
>  (the thread that executes main()), not from a QThread. In GUI 
> applications,
>  the main thread is also called the GUI thread because it's the only 
> thread
>   that is allowed to perform GUI-related operations."

I didn't think that in Linux with NPTL there not even is a thing like a 
"main thread" of a program, but (before binding to a GUI provider) all 
threads of a project are equivalent. As a consequence, multiple  of them 
should be able to be bound to a GUI provider instance - as long as same 
does not impose global variable.

http://www.gentoo.org/doc/en/articles/l-posix1.xml says:

Things are a little more interesting with POSIX threads. You may have 
noticed that I have intentionally avoided using the terms "parent 
thread" and "child thread" so far. That's because with POSIX threads 
this hierarchical relationship doesn't exist. While a main thread may 
create a new thread, and that new thread may create an additional new 
thread, the POSIX threads standard views all your threads as a single 
pool of equals. So the concept of waiting for a child thread to exit 
doesn't make sense. The POSIX threads standard does not record any 
"family" information. This lack of genealogy has one major implication: 
if you want to wait for a thread to terminate, you need to specify which 
one you are waiting for by passing the proper tid to pthread_join(). The 
threads library can't figure it out for you.


More information about the Lazarus mailing list