[Qt-interest] Waking-up a sleeping thread

Andre Somers andre at familiesomers.nl
Fri Jun 11 09:42:32 CEST 2010


On 11-6-2010 9:22, Harry Sfougaris wrote:
> 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
>
>    
Like Scott says: just don't sleep then. You can use signals & slots to 
trigger the lengthy operation once in a while using a timer in your 
thread, and you can use the same signals and slots to quit your thread.

André

-- 
Nokia Certified Qt Developer.
Interested in Qt related job offers or freelance Qt consulting work.




More information about the Qt-interest-old mailing list