+ size_t count = (size_t)s_num, n;
+
+ wxArrayThread threads;
+
+ // first create them all...
+ for ( n = 0; n < count; n++ )
+ {
+ wxThread *thr = CreateThread();
+
+ // we want to show the effect of SetPriority(): the first thread will
+ // have the lowest priority, the second - the highest, all the rest
+ // the normal one
+ if ( n == 0 )
+ thr->SetPriority(WXTHREAD_MIN_PRIORITY);
+ else if ( n == 1 )
+ thr->SetPriority(WXTHREAD_MAX_PRIORITY);
+ else
+ thr->SetPriority(WXTHREAD_DEFAULT_PRIORITY);
+
+ threads.Add(thr);
+ }
+
+ wxString msg;
+ msg.Printf("%d new threads created.", count);
+ SetStatusText(msg, 1);
+
+ // ...and then start them
+ for ( n = 0; n < count; n++ )
+ {
+ threads[n]->Run();
+ }
+}
+
+void MyFrame::OnStartThread(wxCommandEvent& WXUNUSED(event) )
+{
+ MyThread *thread = CreateThread();
+
+ if ( thread->Run() != wxTHREAD_NO_ERROR )
+ {
+ wxLogError("Can't start thread!");
+ }
+
+ SetStatusText("New thread started.", 1);
+}
+
+void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) )
+{
+ // stop the last thread
+ if ( wxGetApp().m_threads.IsEmpty() )
+ {
+ wxLogError("No thread to stop!");
+ }
+ else
+ {
+ wxGetApp().m_critsect.Enter();
+
+ wxThread *thread = wxGetApp().m_threads.Last();
+
+ // it's important to leave critical section before calling Delete()
+ // because delete will (implicitly) call OnExit() which also tries
+ // to enter the same crit section - would dead lock.
+ wxGetApp().m_critsect.Leave();
+
+ thread->Delete();
+
+ SetStatusText("Thread stopped.", 1);
+ }