July 22th Wednesday (七月 二十二日 水曜日)
2009-07-16 16:19
417 查看
A common problem users experience with wxThread is that in their main thread they will check the thread every now and then to
see if it has ended through wxThread::IsRunning, only to find that their application has run into problems because the thread is
using the default behavior and has already deleted itself. Naturally, they instead attempt to use joinable threads in place of
the previous behavior.
However, polling a wxThread for when it has ended is in general a bad idea - in fact calling a routine on any running wxThread
should be avoided if possible. Instead, find a way to notify yourself when the thread has ended. Usually you only need to notify
the main thread, in which case you can post an event to it via wxPostEvent or wxEvtHandler::AddPendingEvent. In the case of secondary
threads you can call a routine of another class when the thread is about to complete processing and/or set the value of a variable,
possibly using mutexes and/or other synchronization means if necessary.
see if it has ended through wxThread::IsRunning, only to find that their application has run into problems because the thread is
using the default behavior and has already deleted itself. Naturally, they instead attempt to use joinable threads in place of
the previous behavior.
However, polling a wxThread for when it has ended is in general a bad idea - in fact calling a routine on any running wxThread
should be avoided if possible. Instead, find a way to notify yourself when the thread has ended. Usually you only need to notify
the main thread, in which case you can post an event to it via wxPostEvent or wxEvtHandler::AddPendingEvent. In the case of secondary
threads you can call a routine of another class when the thread is about to complete processing and/or set the value of a variable,
possibly using mutexes and/or other synchronization means if necessary.
相关文章推荐
- August 22th Wednesday (八月 二十二日 水曜日)
- 2008 July 30th Wednesday (七月 三十日 水曜日)
- July 4th Wednesday (七月 四日 水曜日)
- 2008 July 22th Tuesday (七月 二十二日 火曜日)
- July 18th Wednesday (七月 十八日 水曜日)
- 2008 July 9th Wednesday (七月 九日 水曜日)
- July 15th Wednesday (七月 十五日 水曜日)
- April 22th Wednesday (四月 二十二日 水曜日)
- July 29th Wednesday (七月 二十九日 水曜日)
- 2008 July 23th Wednesday (七月 二十三日 水曜日)
- July 8th Wednesday (七月 八日 水曜日)
- July 11th Wednesday (七月 十一日 水曜日)
- 2008 July 2nd Wednesday (七月 二日 水曜日)
- July 25th Wednesday (七月 二十五日 水曜日)
- July 1st Wednesday (七月 一日 水曜日)
- 2008 July 16th Wenesday (七月 十六日 水曜日)
- May 9th Wednesday (五月 九日 水曜日)
- July 3th Tuesday (七月 三日 火曜日)
- July 13th Friday (七月 十三日 金曜日)
- July 26th Thursday (七月 二十六日 木曜日)