// Author: Original from Wolfram Gloger/Guilhem Lavaux
// Modified by: K. S. Sreeram (2002): POSIXified wxCondition, added wxSemaphore
// Created: 04/22/98
-// RCS-ID: $Id$
// Copyright: (c) Wolfram Gloger (1996, 1997)
// Guilhem Lavaux (1998)
// Vadim Zeitlin (1999-2002)
// id
pthread_t GetId() const { return m_threadId; }
pthread_t *GetIdPtr() { return &m_threadId; }
+ // "created" flag
+ bool WasCreated() const { return m_created; }
// "cancelled" flag
void SetCancelFlag() { m_cancelled = true; }
bool WasCancelled() const { return m_cancelled; }
wxThreadState m_state; // see wxThreadState enum
int m_prio; // in wxWidgets units: from 0 to 100
+ // this flag is set when the thread was successfully created
+ bool m_created;
+
// this flag is set when the thread should terminate
bool m_cancelled;
wxTRY
{
- pthread->m_exitcode = thread->Entry();
+ pthread->m_exitcode = thread->CallEntry();
wxLogTrace(TRACE_THREADS,
wxT("Thread %p Entry() returned %lu."),
wxThreadInternal::wxThreadInternal()
{
m_state = STATE_NEW;
+ m_created = false;
m_cancelled = false;
m_prio = wxPRIORITY_DEFAULT;
m_threadId = 0;
return wxTHREAD_NO_RESOURCE;
}
+ m_created = true;
return wxTHREAD_NO_ERROR;
}
{
wxCriticalSectionLocker lock(m_critsect);
- wxCHECK_MSG( m_internal->GetId(), wxTHREAD_MISC_ERROR,
- wxT("must call wxThread::Create() first") );
+ // Create the thread if it wasn't created yet with an explicit
+ // Create() call:
+ if ( !m_internal->WasCreated() )
+ {
+ wxThreadError rv = m_internal->Create(this, 0);
+ if ( rv != wxTHREAD_NO_ERROR )
+ return rv;
+ }
return m_internal->Run();
}