This is the base class for Guiliani threads.
Derive from this class if you want to create user threads and implement at least the Execute() method. Additionally, you may implement Setup() and Cleanup() to suit your needs.
- Notes for porting Guiliani
- The implementation of this base class in the Guiliani core only provides the platform-independent methods. When porting Guiliani to a new platform, the following methods of CGUIThread have to be implemented:
Thread class example:
class CExampleThread:
{
public:
private:
{
GUILOG(GUI_TRACE_DEBUG, "Parameter: "+eC_String(*(static_cast<eC_UInt*>(pArg)))+".\n");
for (eC_UInt i=0; i < *(static_cast<eC_UInt*>(pArg)); i++)
{
GUILOG(GUI_TRACE_DEBUG, "ExampleThread: "+eC_String(i)+".\n");
eC_Wait(5000);
}
}
};
This is the base class for Guiliani threads.
Definition: GUIThread.h:85
virtual void Setup()
Definition: GUIThread.h:172
virtual void Execute(void *pArg)=0
virtual void Cleanup()
Definition: GUIThread.h:183
Create and execute thread example:
CExampleThread *pThread = new CExampleThread();
eC_UInt uiParam = 10;
pThread->Start((void*)&uiParam);
void CGUIThread::Terminate |
( |
| ) |
|
Terminates the thread.
- Note
- This method may have platform-dependant side effects and should never be used in order to ensure a reliable platform-agnostic application. For example, destructors of objects created in the thread context will not be called when a thread is terminated.
On Windows (where TerminateThread() is called): Note that the MSDN documentation states "TerminateThread is a dangerous function that should only be used in the most extreme cases". The value 0xdeadbeef will be passed to TerminateThread() as dwExitCode.
On Linux (where pthread_cancel() is called): This will interfere with certain ways of exception handling since a abi::__forced_unwind exception will be thrown and must not be intercepted. If a catch-all is implemented in a user-derived thread class, this exception will need to be rethrown:
try
{
}
catch (abi::__forced_unwind&)
{
throw;
}
catch (...)
{
}
On other platforms this may be empty (as in the dummy thread) or execute arbitrary platform-specific code.
Again, when writing a Guiliani application this method should never be used. Guiliani will only use Terminate() in case a still running thread is destroyed, which will not happen during normal operation.