Call wxThread::Create() from Run() automatically.
In the common case, when Run() is called immediately after Create() and default stack size is used, it's unnecessarily verbose. Just create the thread in Run() if it wasn't done explicitly yet. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73999 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -51,8 +51,6 @@ enum wxCondError
|
||||
{
|
||||
m_mutex = mutex;
|
||||
m_condition = condition;
|
||||
|
||||
Create();
|
||||
}
|
||||
|
||||
virtual ExitCode Entry()
|
||||
@@ -772,26 +770,17 @@ enum wxThreadError
|
||||
{
|
||||
m_pThread = new MyThread(this);
|
||||
|
||||
if ( m_pThread->Create() != wxTHREAD_NO_ERROR )
|
||||
if ( m_pThread->Run() != wxTHREAD_NO_ERROR )
|
||||
{
|
||||
wxLogError("Can't create the thread!");
|
||||
delete m_pThread;
|
||||
m_pThread = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_pThread->Run() != wxTHREAD_NO_ERROR )
|
||||
{
|
||||
wxLogError("Can't create the thread!");
|
||||
delete m_pThread;
|
||||
m_pThread = NULL;
|
||||
}
|
||||
|
||||
// after the call to wxThread::Run(), the m_pThread pointer is "unsafe":
|
||||
// at any moment the thread may cease to exist (because it completes its work).
|
||||
// To avoid dangling pointers OnThreadExit() will set m_pThread
|
||||
// to NULL when the thread dies.
|
||||
}
|
||||
// after the call to wxThread::Run(), the m_pThread pointer is "unsafe":
|
||||
// at any moment the thread may cease to exist (because it completes its work).
|
||||
// To avoid dangling pointers OnThreadExit() will set m_pThread
|
||||
// to NULL when the thread dies.
|
||||
}
|
||||
|
||||
wxThread::ExitCode MyThread::Entry()
|
||||
@@ -932,8 +921,7 @@ enum wxThreadError
|
||||
|
||||
All threads other than the "main application thread" (the one running
|
||||
wxApp::OnInit() or the one your main function runs in, for example) are
|
||||
considered "secondary threads". These include all threads created by Create()
|
||||
or the corresponding constructors.
|
||||
considered "secondary threads".
|
||||
|
||||
GUI calls, such as those to a wxWindow or wxBitmap are explicitly not safe
|
||||
at all in secondary threads and could end your application prematurely.
|
||||
@@ -985,7 +973,7 @@ public:
|
||||
/**
|
||||
This constructor creates a new detached (default) or joinable C++
|
||||
thread object. It does not create or start execution of the real thread -
|
||||
for this you should use the Create() and Run() methods.
|
||||
for this you should use the Run() method.
|
||||
|
||||
The possible values for @a kind parameters are:
|
||||
- @b wxTHREAD_DETACHED - Creates a detached thread.
|
||||
@@ -1012,7 +1000,13 @@ public:
|
||||
to it (Ignored on platforms that don't support setting it explicitly,
|
||||
eg. Unix system without @c pthread_attr_setstacksize).
|
||||
|
||||
If you do not specify the stack size,the system's default value is used.
|
||||
If you do not specify the stack size, the system's default value is used.
|
||||
|
||||
@note
|
||||
It is not necessary to call this method since 2.9.5, Run() will create
|
||||
the thread internally. You only need to call Create() if you need to do
|
||||
something with the thread (e.g. pass its ID to an external library)
|
||||
before it starts.
|
||||
|
||||
@warning
|
||||
It is a good idea to explicitly specify a value as systems'
|
||||
@@ -1191,7 +1185,7 @@ public:
|
||||
wxThreadError Resume();
|
||||
|
||||
/**
|
||||
Starts the thread execution. Should be called after Create().
|
||||
Starts the thread execution.
|
||||
|
||||
Note that once you Run() a @b detached thread, @e any function call you do
|
||||
on the thread pointer (you must allocate it on the heap) is @e "unsafe";
|
||||
@@ -1222,8 +1216,6 @@ public:
|
||||
/**
|
||||
Sets the priority of the thread, between 0 (lowest) and 100 (highest).
|
||||
|
||||
It can only be set after calling Create() but before calling Run().
|
||||
|
||||
The following symbolic constants can be used in addition to raw
|
||||
values in 0..100 range:
|
||||
- ::wxPRIORITY_MIN: 0
|
||||
|
Reference in New Issue
Block a user