replace wxPostEvent with wxQueueEvent and update the thread sample description (the sample doesn't shows usage of wxMutexGuiEnter/Leave)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57449 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -895,20 +895,19 @@ how tooltips can be centrally disabled and their latency controlled.
|
|||||||
@section page_samples_thread Thread Sample
|
@section page_samples_thread Thread Sample
|
||||||
|
|
||||||
This sample demonstrates use of threads in connection with GUI programs.
|
This sample demonstrates use of threads in connection with GUI programs.
|
||||||
|
|
||||||
There are two fundamentally different ways to use threads in GUI programs and
|
There are two fundamentally different ways to use threads in GUI programs and
|
||||||
either way has to take care of the fact that the GUI library itself usually
|
either way has to take care of the fact that the GUI library itself usually
|
||||||
is not multi-threading safe, i.e. that it might crash if two threads try to
|
is not multi-threading safe, i.e. that it might crash if two threads try to
|
||||||
access the GUI class simultaneously. One way to prevent that is have a normal
|
access the GUI class simultaneously.
|
||||||
GUI program in the main thread and some worker threads which work in the
|
|
||||||
background. In order to make communication between the main thread and the
|
|
||||||
worker threads possible, wxWidgets offers the wxPostEvent
|
|
||||||
function and this sample makes use of this function.
|
|
||||||
|
|
||||||
The other way to use a so called Mutex (such as those offered in the wxMutex
|
One way to prevent that is have a normal GUI program in the main thread and some
|
||||||
class) that prevent threads from accessing the GUI classes as long as any other
|
worker threads which work in the background. In order to make communication between
|
||||||
thread accesses them. For this, wxWidgets has the wxMutexGuiEnter
|
the main thread and the worker threads possible, wxWidgets offers the ::wxQueueEvent
|
||||||
and wxMutexGuiLeave functions, both of which are
|
function and this sample demonstrates its usage.
|
||||||
used and tested in the sample as well.
|
|
||||||
|
The other way is to use a ::wxMutexGuiEnter and ::wxMutexGuiLeave functions, but
|
||||||
|
this is not currently shown in the sample.
|
||||||
|
|
||||||
See also @ref overview_thread and wxThread.
|
See also @ref overview_thread and wxThread.
|
||||||
|
|
||||||
|
@@ -305,14 +305,14 @@ void *MyWorkerThread::Entry()
|
|||||||
event.SetInt( m_count );
|
event.SetInt( m_count );
|
||||||
|
|
||||||
// send in a thread-safe way
|
// send in a thread-safe way
|
||||||
wxPostEvent( m_frame, event );
|
wxQueueEvent( m_frame, new wxCommandEvent(event) );
|
||||||
|
|
||||||
wxMilliSleep(200);
|
wxMilliSleep(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, WORKER_EVENT );
|
wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, WORKER_EVENT );
|
||||||
event.SetInt(-1); // that's all
|
event.SetInt(-1); // that's all
|
||||||
wxPostEvent( m_frame, event );
|
wxQueueEvent( m_frame, new wxCommandEvent(event) );
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -416,7 +416,7 @@ bool MyApp::OnInit()
|
|||||||
menuBar->Append(menuHelp, _T("&Help"));
|
menuBar->Append(menuHelp, _T("&Help"));
|
||||||
|
|
||||||
frame->SetMenuBar(menuBar);
|
frame->SetMenuBar(menuBar);
|
||||||
|
|
||||||
// Show the frame
|
// Show the frame
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
|
|
||||||
@@ -431,7 +431,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title,
|
|||||||
: wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
: wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
||||||
{
|
{
|
||||||
SetIcon(wxIcon(sample_xpm));
|
SetIcon(wxIcon(sample_xpm));
|
||||||
|
|
||||||
m_nRunning = m_nCount = 0;
|
m_nRunning = m_nCount = 0;
|
||||||
|
|
||||||
m_dlgProgress = (wxProgressDialog *)NULL;
|
m_dlgProgress = (wxProgressDialog *)NULL;
|
||||||
|
Reference in New Issue
Block a user