[Qt-interest] Waking-up a sleeping thread
Harry Sfougaris
hsfougaris at gmail.com
Fri Jun 11 16:48:46 CEST 2010
Actually that's how I ended up implementing it, with the exception of running the timer on the main thread.
It seems to work fine.
Thanks,
Harry
On 11 Ιουν 2010, at 5:34 μ.μ., Scott Bloom wrote:
> Why not have a singleshot timer that called from the thread constructor and
> at the end of processing?
>
> Just make sure the threads event loop gets kicked off
>
> Scott
>
>
> On 6/11/10 12:38 AM, "Harry Sfougaris" <hsfougaris at gmail.com> wrote:
>
>> Well I need to check a remote database server if there is data available (I
>> can't use notify).
> Since there are many ways this can fail , I need to do it
>> in a thread.
> I can't think of another way to do it.
>
> Harry
>
> On 11 Ιουν 2010,
>> at 10:34 π.μ., Scott Aron Bloom wrote:
>
>> Don't use sleep..
>>
>> One
>> suggestion, that has worked for me.. rather than calling sleep..
>> only start
>> the thread when you have info to process.. otherwise exit
>> out.
>>
>> Scott
>>
>>
>>
>>
>> -----Original Message-----
>> From:
>> qt-interest-bounces at trolltech.com
>> [mailto:qt-interest-bounces at trolltech.com]
>> On Behalf Of Harry Sfougaris
>> Sent: Friday, June 11, 2010 12:23 AM
>> To:
>> qt-interest at trolltech.com
>> Subject: [Qt-interest] Waking-up a sleeping
>> thread
>>
>> Is it possible to "wake-up" a thread, after calling sleep(secs) on
>> it?
>> I have a thread that periodically does a job. I have the following
>>
>> pseudocode in the run() function of my thread:
>> ...
>> while (!stopped) {
>>
>> sleep( jobInterval);
>> if (stopped) break;
>> doLengthyTask();
>> }
>> ...
>>
>> my thread deconstructor is
>> myThread::~myThread() {
>> stopped = true;
>>
>> wait();
>> }
>>
>> My problem is when the user tries to exit the app, the
>> program will
>> stall for up to jobInterval seconds, as the thread might be
>> sleeping,
>> and the deconstructor waits for it.
>> Is there another way to
>> handle this?
>>
>> Thanks,
>> Harry
>>
>>
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>>
>> Qt-interest at trolltech.com
>>
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> ____________________
>> ___________________________
> 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