📄 thread.tex
字号:
\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 along. This can be used to uniquely identify threads, even if they arenot wxThreads.\membersection{wxThread::GetId}\label{wxthreadgetid}\constfunc{unsigned long}{GetId}{\void}Gets the thread identifier: this is a platform dependent number that uniquely identifies thethread 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, notdetached ones as the latter delete themselves and so when the real thread isno longer alive, it is not possible to call this function becausethe 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 joinableone.\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 shouldbe used with extreme care (and not used at all whenever possible)!} The resourcesallocated to the thread will not be freed and the state of the C runtime librarymay 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 willstill have to delete the wxThread object yourself to avoid memory leaks.In neither case \helpref{OnExit}{wxthreadonexit} of the dying thread will becalled, so no thread-specific cleanup will be performed.This function can only be called from another thread context, i.e. a threadcannot kill itself.It is also an error to call this function for a thread which is not running orpaused (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 thethread associated with the wxThread object, not in the context of the mainthread. 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 issuspended immediately, under others it will only be suspended when it calls\helpref{TestDestroy}{wxthreadtestdestroy} for the next time (hence, if thethread 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 setafter 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 workerthreads (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, thenumber 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 isnot 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 callsto \helpref{Pause}{wxthreadpause} and \helpref{Delete}{wxthreaddelete} willwork. 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, sonot 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 threadis the main (GUI) thread, but \helpref{IsMain}{wxthreadismain} should be used to testwhether the thread is really the main one because NULL may also be returned for the threadnot created with wxThread class. Generally speaking, the return value for such a threadis 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -