thread.tex

来自「Wxpython Implemented on Windows CE, Sou」· TEX 代码 · 共 474 行 · 第 1/2 页

TEX
474
字号
Returns the number of system CPUs or -1 if the value is unknown.

\wxheading{See also}

\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}

Gets the thread identifier: this is a platform dependent number that uniquely identifies the
thread throughout the system during its existence (i.e. the thread identifiers may be reused).


\membersection{wxThread::GetPriority}\label{wxthreadgetpriority}

\constfunc{int}{GetPriority}{\void}

Gets the priority of the thread, between zero and 100.

The following priorities are defined:

\twocolwidtha{7cm}
\begin{twocollist}\itemsep=0pt
\twocolitem{{\bf WXTHREAD\_MIN\_PRIORITY}}{0}
\twocolitem{{\bf WXTHREAD\_DEFAULT\_PRIORITY}}{50}
\twocolitem{{\bf WXTHREAD\_MAX\_PRIORITY}}{100}
\end{twocollist}


\membersection{wxThread::IsAlive}\label{wxthreadisalive}

\constfunc{bool}{IsAlive}{\void}

Returns \true if the thread is alive (i.e. started and not terminating).

Note that this function can only safely be used with joinable threads, not
detached ones as the latter delete themselves and so when the real thread is
no longer alive, it is not possible to call this function because
the wxThread object no longer exists.

\membersection{wxThread::IsDetached}\label{wxthreadisdetached}

\constfunc{bool}{IsDetached}{\void}

Returns \true if the thread is of the detached kind, \false if it is a joinable
one.


\membersection{wxThread::IsMain}\label{wxthreadismain}

\func{static bool}{IsMain}{\void}

Returns \true if the calling thread is the main application thread.


\membersection{wxThread::IsPaused}\label{wxthreadispaused}

\constfunc{bool}{IsPaused}{\void}

Returns \true if the thread is paused.


\membersection{wxThread::IsRunning}\label{wxthreadisrunning}

\constfunc{bool}{IsRunning}{\void}

Returns \true if the thread is running.

This method may only be safely used for joinable threads, see the remark in 
\helpref{IsAlive}{wxthreadisalive}.


\membersection{wxThread::Kill}\label{wxthreadkill}

\func{wxThreadError}{Kill}{\void}

Immediately terminates the target thread. {\bf This function is dangerous and should
be used with extreme care (and not used at all whenever possible)!} The resources
allocated to the thread will not be freed and the state of the C runtime library
may become inconsistent. Use \helpref{Delete()}{wxthreaddelete} for detached 
threads or \helpref{Wait()}{wxthreadwait} for joinable threads instead.

For detached threads Kill() will also delete the associated C++ object.
However this will not happen for joinable threads and this means that you will
still have to delete the wxThread object yourself to avoid memory leaks.
In neither case \helpref{OnExit}{wxthreadonexit} of the dying thread will be
called, so no thread-specific cleanup will be performed.

This function can only be called from another thread context, i.e. a thread
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,
a {\tt wxTHREAD\_NOT\_RUNNING} error will be returned.


\membersection{wxThread::OnExit}\label{wxthreadonexit}

\func{void}{OnExit}{\void}

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
\helpref{killed}{wxthreadkill}.

This function should never be called directly.


\membersection{wxThread::Pause}\label{wxthreadpause}

\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
\helpref{TestDestroy}{wxthreadtestdestroy} for the next time (hence, if the
thread doesn't call it at all, it won't be suspended).

This function can only be called from another thread context.


\membersection{wxThread::Run}\label{wxthreadrun}

\func{wxThreadError}{Run}{\void}

Starts the thread execution. Should be called after
\helpref{Create}{wxthreadcreate}.

This function can only be called from another thread context.


\membersection{wxThread::SetPriority}\label{wxthreadsetpriority}

\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
\helpref{Run()}{wxthreadrun}.

The following priorities are already defined:

\twocolwidtha{7cm}
\begin{twocollist}\itemsep=0pt
\twocolitem{{\bf WXTHREAD\_MIN\_PRIORITY}}{0}
\twocolitem{{\bf WXTHREAD\_DEFAULT\_PRIORITY}}{50}
\twocolitem{{\bf WXTHREAD\_MAX\_PRIORITY}}{100}
\end{twocollist}


\membersection{wxThread::Sleep}\label{wxthreadsleep}

\func{static void}{Sleep}{\param{unsigned long }{milliseconds}}

Pauses the thread execution for the given amount of time.

This function should be used instead of \helpref{wxSleep}{wxsleep} by all worker
threads (i.e. all except the main one).


\membersection{wxThread::Resume}\label{wxthreadresume}

\func{wxThreadError}{Resume}{\void}

Resumes a thread suspended by the call to \helpref{Pause}{wxthreadpause}.

This function can only be called from another thread context.


\membersection{wxThread::SetConcurrency}\label{wxthreadsetconcurrency}

\func{static bool}{SetConcurrency}{\param{size\_t }{level}}

Sets the thread concurrency level for this process. This is, roughly, the
number of threads that the system tries to schedule to run in parallel.
The value of $0$ for {\it level} may be used to set the default one.

Returns \true on success or false otherwise (for example, if this function is
not implemented for this platform -- currently everything except Solaris).


\membersection{wxThread::TestDestroy}\label{wxthreadtestdestroy}

\func{virtual bool}{TestDestroy}{\void}

This function should be called periodically by the thread to ensure that calls
to \helpref{Pause}{wxthreadpause} and \helpref{Delete}{wxthreaddelete} will
work. If it returns \true, the thread should exit as soon as possible.

Notice that under some platforms (POSIX), implementation of 
\helpref{Pause}{wxthreadpause} also relies on this function being called, so
not calling it would prevent both stopping and suspending thread from working.


\membersection{wxThread::This}\label{wxthreadthis}

\func{static wxThread *}{This}{\void}

Return the thread object for the calling thread. NULL is returned if the calling thread
is the main (GUI) thread, but \helpref{IsMain}{wxthreadismain} should be used to test
whether the thread is really the main one because NULL may also be returned for the thread
not created with wxThread class. Generally speaking, the return value for such a thread
is undefined.


\membersection{wxThread::Yield}\label{wxthreadyield}

\func{void}{Yield}{\void}

Give the rest of the thread time slice to the system allowing the other threads to run.
See also \helpref{Sleep()}{wxthreadsleep}.


\membersection{wxThread::Wait}\label{wxthreadwait}

\constfunc{ExitCode}{Wait}{\void}

Gracefully terminates a joinable thread, either when the thread calls 
\helpref{TestDestroy}{wxthreadtestdestroy} or finished processing, and 
returns the value the thread returned from 
\helpref{wxThread::Entry}{wxthreadentry} or {\tt (ExitCode)-1} on error. 

You can only Wait() for joinable (not detached) threads.

This function can only be called from another thread context.

See \helpref{wxThread deletion}{deletionwxthread} for a broader explanation of this routine.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?