wxthreadhelperthe wxthreadhelper class is a mix-in class that manages a single background thread. by deriving from wxthreadhelper, a class can implement the thread code in its own wxthreadhelper::entry method and easily share data and synchronization objects between the main thread and the worker thread. doing this prevents the awkward passing of pointers that is needed when the original object in the main thread needs to synchronize with its worker thread in its own wxthread derived object. for example, wxframe may need to make some calculations in a background thread and then display the results of those calculations in the main window. ordinarily, a wxthread derived object would be created with the calculation code implemented in wxthread::entry. to access the inputs to the calculation, the frame object would often to pass a pointer to itself to the thread object. similarly, the frame object would hold a pointer to the thread object. shared data and synchronization objects could be stored in either object though the object without the data would have to access the data through a pointer. however, with wxthreadhelper, the frame object and the thread object are treated as the same object. shared data and synchronization variables are stored in the single object, eliminating a layer of indirection and the associated pointers. derived from none. include files <wx/thread.h> see also members
wxthreadhelper::wxthreadhelper
wxthreadhelper::wxthreadhelperwxthreadhelper() this constructor simply initializes a member variable.
wxthreadhelper::m_threadwxthread * m_thread the actual wxthread object.
wxthreadhelper::~wxthreadhelper~wxthreadhelper() the destructor frees the resources associated with the thread.
wxthreadhelper::createwxthreaderror create(unsigned int stacksize = 0) creates a new thread. the thread object is created in the suspended state, and you should call getthread()->run() to start running it. you may optionally specify the stack size to be allocated to it (ignored on platforms that don't support setting it explicitly, eg. unix). return value one of:
wxthreadhelper::entryvirtual exitcode entry() this is the entry point of the thread. this function is pure virtual and must be implemented by any derived class. the thread execution will start here. the returned value is the thread exit code which is only useful for joinable threads and is the value returned by getthread()->wait(). this function is called by wxwidgets itself and should never be called directly.
wxthreadhelper::getthreadwxthread * getthread() this is a public function that returns the wxthread object associated with the thread.
|