スレッドを終了し、私はwxThreadから派生したクラスのオブジェクトの内部GUI的環境としてwxWidgetsの - 正しい方法
をwxWidgetを使用するOpenCL/OpenGLのプログラムを実行するには、私はいくつかの複雑な計算を実行し、多くのOpenCLプログラムを構築します。 私はスレッドを削除したいですが、スレッドは即座に削除されません。プログラムをビルドし続け、すべてのコンパイルが終了した直後にスレッドを削除します。
私はwxThread::KIll()
を使用してスレッドを終了することができますが、メモリの問題が発生するため、実際にはオプションではありません。私はwxFrame.it由来するMyFrameとクラスはpCanvasオブジェクトは(複雑な計算を実行する)myThread
void myFrame::onExit(wxCommandEvent& WXUNUSED(event))
{
if(_pCanvas != NULL)
{
wxCriticalSectionLocker enter(_smokeThreadCS);
// smoke thread still exists
if (_pCanvas->getThread() != NULL)
{
//_pCanvas->getSmokeThread()->Delete(); <-waits until thread ends and after it application terminates
_pCanvas->getSmokeThread()->Kill(); <- immediately makes the application not responding
}
}
// exit from the critical section to give the thread
// the possibility to enter its destructor
// (which is guarded with m_pThreadCS critical section!)
while (true)
{
{ // was the ~MyThread() function executed?
wxCriticalSectionLocker enter(_smokeThreadCS);
if (!_pCanvas->getSmokeThread()) break;
}
// wait for thread completion
wxThread::This()->Sleep(1);
}
DestroyChildren();
Destroy();
// Close the main frame, this ends the application run:
Close(true);
}
IIUCスレッドがクリティカルセクションを取得し、殺害を行っているスレッドは殺されていませんか? –
そのようなスレッドを殺すことは良い考えではありません。 –