thread, even if it is not a wxThread.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13595
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
\func{}{\destruct{wxThread}}{\void}
The destructor frees the resources associated with the thread. Notice that you
\func{}{\destruct{wxThread}}{\void}
The destructor frees the resources associated with the thread. Notice that you
-should never delete a detached thread - you may only call
+should never delete a detached thread - you may only call
\helpref{Delete}{wxthreaddelete} on it or wait until it terminates (and auto
destructs) itself. Because the detached threads delete themselves, they can
only be allocated on the heap.
\helpref{Delete}{wxthreaddelete} on it or wait until it terminates (and auto
destructs) itself. Because the detached threads delete themselves, they can
only be allocated on the heap.
Calling \helpref{Delete}{wxthreaddelete} is a graceful way to terminate the
thread. It asks the thread to terminate and, if the thread code is well
Calling \helpref{Delete}{wxthreaddelete} is a graceful way to terminate the
thread. It asks the thread to terminate and, if the thread code is well
-written, the thread will terminate after the next call to
+written, the thread will terminate after the next call to
\helpref{TestDestroy}{wxthreadtestdestroy} which should happen quite soon.
\helpref{TestDestroy}{wxthreadtestdestroy} which should happen quite soon.
-However, if the thread doesn't call \helpref{TestDestroy}{wxthreadtestdestroy}
+However, if the thread doesn't call \helpref{TestDestroy}{wxthreadtestdestroy}
often enough (or at all), the function will not return immediately, but wait
until the thread terminates. As it may take a long time, and the message processing
is not stopped during this function execution, message handlers may be
called from inside it!
Delete() may be called for thread in any state: running, paused or even not yet
often enough (or at all), the function will not return immediately, but wait
until the thread terminates. As it may take a long time, and the message processing
is not stopped during this function execution, message handlers may be
called from inside it!
Delete() may be called for thread in any state: running, paused or even not yet
-created. Moreover, it must be called if \helpref{Create}{wxthreadcreate} or
+created. Moreover, it must be called if \helpref{Create}{wxthreadcreate} or
\helpref{Run}{wxthreadrun} failed for a detached thread to free the memory
occupied by the thread object. This cleanup will be done in the destructor for joinable
threads.
\helpref{Run}{wxthreadrun} failed for a detached thread to free the memory
occupied by the thread object. This cleanup will be done in the destructor for joinable
threads.
thread, i.e. a thread can only exit from itself, not from another thread.
This function will terminate the OS thread (i.e. stop the associated path of
thread, i.e. a thread can only exit from itself, not from another thread.
This function will terminate the OS thread (i.e. stop the associated path of
-execution) and also delete the associated C++ object for detached threads.
+execution) and also delete the associated C++ object for detached threads.
\helpref{wxThread::OnExit}{wxthreadonexit} will be called just before exiting.
\membersection{wxThread::GetCPUCount}\label{wxthreadgetcpucount}
\helpref{wxThread::OnExit}{wxthreadonexit} will be called just before exiting.
\membersection{wxThread::GetCPUCount}\label{wxthreadgetcpucount}
\helpref{SetConcurrency}{wxthreadsetconcurrency}
\helpref{SetConcurrency}{wxthreadsetconcurrency}
+\membersection{wxThread::GetCurrentId}\label{wxthreadgetcurrentid}
+
+\func{static unsigned long}{GetCurrentId}{\void}
+
+Returns the platform specific thread ID of the current thread as a
+long. This can be used to uniquely identify threads, even if they are
+not wxThreads.
+
\membersection{wxThread::GetId}\label{wxthreadgetid}
\constfunc{unsigned long}{GetId}{\void}
\membersection{wxThread::GetId}\label{wxthreadgetid}
\constfunc{unsigned long}{GetId}{\void}
cannot kill itself.
It is also an error to call this function for a thread which is not running or
cannot kill itself.
It is also an error to call this function for a thread which is not running or
-paused (in the latter case, the thread will be resumed first) - if you do it,
+paused (in the latter case, the thread will be resumed first) - if you do it,
a {\tt wxTHREAD\_NOT\_RUNNING} error will be returned.
\membersection{wxThread::OnExit}\label{wxthreadonexit}
a {\tt wxTHREAD\_NOT\_RUNNING} error will be returned.
\membersection{wxThread::OnExit}\label{wxthreadonexit}
Called when the thread exits. This function is called in the context of the
thread associated with the wxThread object, not in the context of the main
Called when the thread exits. This function is called in the context of the
thread associated with the wxThread object, not in the context of the main
-thread. This function will not be called if the thread was
+thread. This function will not be called if the thread was
\helpref{killed}{wxthreadkill}.
This function should never be called directly.
\helpref{killed}{wxthreadkill}.
This function should never be called directly.
\func{wxThreadError}{Pause}{\void}
Suspends the thread. Under some implementations (Win32), the thread is
\func{wxThreadError}{Pause}{\void}
Suspends the thread. Under some implementations (Win32), the thread is
-suspended immediately, under others it will only be suspended when it calls
+suspended immediately, under others it will only be suspended when it calls
\helpref{TestDestroy}{wxthreadtestdestroy} for the next time (hence, if the
thread doesn't call it at all, it won't be suspended).
\helpref{TestDestroy}{wxthreadtestdestroy} for the next time (hence, if the
thread doesn't call it at all, it won't be suspended).
\func{wxThreadError}{Run}{\void}
\func{wxThreadError}{Run}{\void}
-Starts the thread execution. Should be called after
+Starts the thread execution. Should be called after
\helpref{Create}{wxthreadcreate}.
This function can only be called from another thread context.
\helpref{Create}{wxthreadcreate}.
This function can only be called from another thread context.
\func{void}{SetPriority}{\param{int}{ priority}}
Sets the priority of the thread, between $0$ and $100$. It can only be set
\func{void}{SetPriority}{\param{int}{ priority}}
Sets the priority of the thread, between $0$ and $100$. It can only be set
-after calling \helpref{Create()}{wxthreadcreate} but before calling
+after calling \helpref{Create()}{wxthreadcreate} but before calling
\helpref{Run()}{wxthreadrun}.
The following priorities are already defined:
\helpref{Run()}{wxthreadrun}.
The following priorities are already defined:
// Returns -1 if unknown, number of CPUs otherwise
static int GetCPUCount();
// Returns -1 if unknown, number of CPUs otherwise
static int GetCPUCount();
+ // Get the platform specific thread ID and return as a long. This
+ // can be used to uniquely identify threads, even if they are not
+ // wxThreads. This is used by wxPython.
+ static unsigned long GetCurrentId();
+
// sets the concurrency level: this is, roughly, the number of threads
// the system tries to schedule to run in parallel. 0 means the
// default value (usually acceptable, but may not yield the best
// sets the concurrency level: this is, roughly, the number of threads
// the system tries to schedule to run in parallel. 0 means the
// default value (usually acceptable, but may not yield the best
#else
unsigned long GetId() const;
#endif
#else
unsigned long GetId() const;
#endif
// called when the thread exits - in the context of this thread
//
// NB: this function will not be called if the thread is Kill()ed
// called when the thread exits - in the context of this thread
//
// NB: this function will not be called if the thread is Kill()ed
return si.dwNumberOfProcessors;
}
return si.dwNumberOfProcessors;
}
+unsigned long wxThread::GetCurrentId()
+{
+ return (unsigned long)::GetCurrentThreadId();
+}
+
bool wxThread::SetConcurrency(size_t level)
{
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
bool wxThread::SetConcurrency(size_t level)
{
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
-// TODO: This should really be wxThread::GetCurrentId(), and I will do so
-// after I make a quick 2.3.2.1 release.
-#ifdef __WXGTK__ // does wxGTK always use pthreads?
-#include <unistd.h>
-#include <pthread.h>
-#endif
inline
unsigned long wxPyGetCurrentThreadId() {
inline
unsigned long wxPyGetCurrentThreadId() {
-#ifdef __WXMSW__
- return (unsigned long)::GetCurrentThreadId();
-#endif
-#ifdef __WXGTK__ // does wxGTK always use pthreads?
- return (unsigned long)pthread_self();
-#endif
-#ifdef __WXMAC__
- ThreadID current ;
- MacGetCurrentThread( ¤t ) ;
- return (unsigned long)current;
-#endif
+ return wxThread::GetCurrentId();
static
PyThreadState* wxPyGetThreadState() {
unsigned long ctid = wxPyGetCurrentThreadId();
static
PyThreadState* wxPyGetThreadState() {
unsigned long ctid = wxPyGetCurrentThreadId();