[Qt-interest] Aborting QThreads

Jeffery MacEachern j.maceachern at gmail.com
Sat Jul 10 10:18:09 CEST 2010


On Sat, Jul 10, 2010 at 1:09 AM, Mandeep Sandhu
<mandeepsandhu.chd at gmail.com> wrote:
>> void DataThread::stop()
>> {
>>    qDebug() << "Data Thread preparing to shut down";
>>    m_mutex.lock();
>>    m_abort = true;
>>    m_mutex.unlock();
>>
>>    wait();
>> }
>>
>> The destructor also makes use of this method, so that the hardware can
>> be deactivated gracefully.  What I'm wondering is whether it is more
>> "proper" to include the wait() call in the stop method for
>> convenience, or to expect the user of the thread to call it manually,
>> as they would otherwise have to.
>
> I would prefer to have it inside this fxn as you've shown.
>
> You will anyway have to wait() for the thread to exit while destroying
> your thread object, since if you're deleting your thread object from
> outside (i.e by a user of this class), you will not have a chance to
> do an "explicit" wait() since the thread object would be deleted by
> then. And that could lead to the thread doing an unclean exit.

That sounds sensible.  Thanks for the second opinion.
    - Jeffery MacEachern

> HTH,
> -mandeep
>
>>
>> Thanks,
>>     - Jeffery MacEachern
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>




More information about the Qt-interest-old mailing list