[Qt-interest] Waking-up a sleeping thread

Brad Howes howes at ll.mit.edu
Fri Jun 11 16:49:30 CEST 2010


On Jun 11, 2010, at 3:22 AM, 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();
> }


Before calling wait(), issue cancel() -- I think sleep() is a proper cancellation point for threads, so the cancel() should wake it up immediately.

Brad

-- 
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420









More information about the Qt-interest-old mailing list