[Development] Qthread::create and ::exec

Иван Комиссаров abbapoh at gmail.com
Wed Nov 21 19:27:50 CET 2018



Иван Комиссаров

> 21 нояб. 2018 г., в 16:37, Olivier Goffart <olivier at woboq.com> написал(а):
> 
>> On 21.11.18 16:26, Иван Комиссаров wrote:
>> Except there's possible race-condition if quit() is called before loop started, isn't it? At least, qthread::exec do some checks under mutex
> 
> No, QEventLoop::exec also checks for d->threadData->quitNow

Ok, thanks, I didn't dig that deep.

> The only difference would be the return code.
> (And note that there is a race condition in QThread::exec, which could lead the return code to be lost if QThread::exit() is called right at the moment QThread::exec() is called.)
> 

Heh, that code looked suspicious to me:) I was wondering if I'm missing something but it appears that I don't

Thank's for the clarification.

>> Иван Комиссаров
>>>> 21 нояб. 2018 г., в 16:10, Olivier Goffart <olivier at woboq.com> написал(а):
>>>> 
>>>>> On 21.11.18 15:47, Volker Hilsheimer wrote:
>>>>> On 20 Nov 2018, at 14:30, Иван Комиссаров <abbapoh at gmail.com> wrote:
>>>>> Hello, I've noticed that it would be nice to run QThread::exec() from a functor passed to QThread::create(). However, exec is marked as protected, thus I can't call QThread::currentThread()->exec().
>>>>> Maybe it is worth to make exec() public method? Or make it static, like in QApp (is it BC?)?
>>>>> This would be a nice addition to the create() method so worker objects can be created in a functor on stack instead of moving them to thread.
>>>>> 
>>>>> Иван Комиссаров
>>>> The reason why QThread::exec is protected so that people don’t get tempted to call it directly on a QThread object and expecting that the event loop is somehow executed in a separate thread. It is useful to generate a compile-time error when this is attempted:
>>>> QThread *heyNewThread = new QThread;
>>>> heyNewThread->exec();
>>>> I would rather not remove that limitation (and it would break BC on compilers that include the access level in the generated symbol). Making exec() public would indicate that the above is ok, while it actually breaks the semantics.
>>> 
>>> No need to access QThread::exec().
>>> One can just call
>>> 
>>>   QEventLoop().exec();
>>> 
>>> And that has the same effect.
>>> 
>>> -- 
>>> Olivier
>>> 
>>> Woboq - Qt services and support - https://woboq.com - https://code.woboq.org
>>> _______________________________________________
>>> Development mailing list
>>> Development at lists.qt-project.org
>>> https://lists.qt-project.org/listinfo/development
> 



More information about the Development mailing list