[Development] qthread exiting
Thiago Macieira
thiago.macieira at intel.com
Tue Aug 14 10:27:39 CEST 2012
On terça-feira, 14 de agosto de 2012 07.36.31, song.7.liu at nokia.com wrote:
> Hi,
>
> When the thread is exiting the destroy_current_thread_data will be called,
> and only if the thread data is adopted, the QThreadPrivate::finish is
> called. But normally the thread data always have the isAdopted with false,
> then this thread 's status is still running even if it's exited.
>
> So could somebody share when will the QThreadPrivate::finish be called
> during thread exiting ? And what's the QAdoptedThread for? As only creating
> the AdoptedThread then the thread data' isAdopted will be set as true.
Adopted threads are a weird concept you're likely not going to find. The
adopted threads were invented, as far as I remember, to support Qt Jambi, when
threads were created by the JVM instead of by QThread. But it allows one to
use QObjects and even event-loop items in threads not started with QThread.
QThreadPrivate::finish is run by pthreads cleanup solution. See
QThreadPrivate::start:
pthread_cleanup_push(QThreadPrivate::finish, arg);
[...]
thr->run();
pthread_cleanup_pop(1);
Here we have a perfect example of "The Boolean Trap", with a C twist.
void pthread_cleanup_pop(int execute);
The pthread_cleanup_pop() function removes the routine at the
top of the stack of clean-up handlers, and optionally executes
it if _execute_ is nonzero.
So pthread_cleanup_pop calls finish(), and it's also called in case the thread
is cancelled.
As for destroy_current_thread_data, it's also run by pthreads, maybe at a
different moment. It's a callback by the pthread_specific, added by
pthread_key_create in create_current_thread_data_key.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Intel Sweden AB - Registration Number: 556189-6027
Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120814/68fe71b0/attachment.sig>
More information about the Development
mailing list