]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/thread.tex
If somebody ever decides to actually check in fsfile.tex and
[wxWidgets.git] / docs / latex / wx / thread.tex
CommitLineData
eaaa6a06
JS
1\section{\class{wxThread}}\label{wxthread}
2
6e6110ee 3A thread is basically a path of execution through a program. Threads are also
631f1bfe 4sometimes called {\it light-weight processes}, but the fundamental difference
6e6110ee
VZ
5between threads and processes is that memory spaces of different processes are
6separated while all threads share the same address space. While it makes it
7much easier to share common data between several threads, it also makes much
631f1bfe 8easier to shoot oneself in the foot, so careful use of synchronization objects
28d9589a 9such as \helpref{mutexes}{wxmutex} and/or \helpref{critical sections}{wxcriticalsection} is recommended.
eaaa6a06
JS
10
11\wxheading{Derived from}
12
13None.
14
954b8ae6
JS
15\wxheading{Include files}
16
17<wx/thread.h>
18
eaaa6a06
JS
19\wxheading{See also}
20
e2a6f233 21\helpref{wxMutex}{wxmutex}, \helpref{wxCondition}{wxcondition}, \helpref{wxCriticalSection}{wxcriticalsection}
eaaa6a06
JS
22
23\latexignore{\rtfignore{\wxheading{Members}}}
24
28d9589a 25\membersection{wxThread::wxThread}\label{wxthreadctor}
eaaa6a06
JS
26
27\func{}{wxThread}{\void}
28
28d9589a 29Default constructor: it doesn't create nor starts the thread.
eaaa6a06
JS
30
31\membersection{wxThread::\destruct{wxThread}}
32
33\func{}{\destruct{wxThread}}{\void}
34
28d9589a
VZ
35wxThread destructor is private, so you can not call it directly - i.e., deleting
36wxThread objects is forbidden. Instead, you should use \helpref{Delete}{wxthreaddelete} or
37\helpref{Kill}{wxthreadkill} methods. This also means that thread objects should
38eb {\bf always} allocated on the heap (i.e. with {\it new}) because the functions
39mentioned above will try to reclaim the storage from the heap.
eaaa6a06
JS
40
41\membersection{wxThread::Create}\label{wxthreadcreate}
42
43\func{wxThreadError}{Create}{\void}
44
28d9589a
VZ
45Creates a new thread. The thread object is created in the suspended state, you
46should call \helpref{Run}{wxthreadrun} to start running it.
eaaa6a06
JS
47
48\wxheading{Return value}
49
50One of:
51
52\twocolwidtha{7cm}
53\begin{twocollist}\itemsep=0pt
6e6110ee
VZ
54\twocolitem{{\bf wxTHREAD\_NO\_ERROR}}{There was no error.}
55\twocolitem{{\bf wxTHREAD\_NO\_RESOURCE}}{There were insufficient resources to create a new thread.}
56\twocolitem{{\bf wxTHREAD\_RUNNING}}{The thread is already running.}
eaaa6a06
JS
57\end{twocollist}
58
28d9589a 59\membersection{wxThread::Delete}\label{wxthreaddelete}
eaaa6a06 60
43191e0c 61\func{void}{Delete}{\void}
eaaa6a06 62
28d9589a
VZ
63This function should be called to terminate this thread. Unlike \helpref{Kill}{wxthreadkill}, it
64gives the target thread the time to terminate gracefully. Because of this, however, this function
65may not return immediately and if the thread is "hung" won't return at all. Also, message processing
66is not stopped during this function execution, so the message handlers may be called from inside
67it.
eaaa6a06 68
28d9589a
VZ
69Delete() may be called for thread in any state: running, paused or even not yet created. Moreover,
70it must be called if \helpref{Create}{wxthreadcreate} or \helpref{Run}{wxthreadrun} fail to free
71the memory occupied by the thread object.
eaaa6a06 72
43191e0c
VZ
73\membersection{wxThread::Entry}\label{wxthreadentry}
74
75\func{virtual void *}{Entry}{\void}
76
77This is the entry point of the thread. This function is pure virtual and must
78be implemented by any derived class. The thread execution will start here.
79
80The returned value is the thread exit code but is currently ignored in
81wxWindows implementation (this will change in near future).
82
eaaa6a06
JS
83\membersection{wxThread::GetID}\label{wxthreadgetid}
84
85\constfunc{unsigned long}{GetID}{\void}
86
28d9589a
VZ
87Gets the thread identifier: this is a platform dependent number which uniquely identifies the
88thread throughout the system during its existence (i.e. the thread identifiers may be reused).
eaaa6a06
JS
89
90\membersection{wxThread::GetPriority}\label{wxthreadgetpriority}
91
92\constfunc{int}{GetPriority}{\void}
93
94Gets the priority of the thread, between zero and 100.
95
96The following priorities are already defined:
97
98\twocolwidtha{7cm}
99\begin{twocollist}\itemsep=0pt
e14dccff
KB
100\twocolitem{{\bf WXTHREAD\_MIN\_PRIORITY}}{0}
101\twocolitem{{\bf WXTHREAD\_DEFAULT\_PRIORITY}}{50}
102\twocolitem{{\bf WXTHREAD\_MAX\_PRIORITY}}{100}
eaaa6a06
JS
103\end{twocollist}
104
105\membersection{wxThread::IsAlive}\label{wxthreadisalive}
106
107\constfunc{bool}{IsAlive}{\void}
108
28d9589a 109Returns TRUE if the thread is alive (i.e. started and not terminating).
eaaa6a06
JS
110
111\membersection{wxThread::IsMain}\label{wxthreadismain}
112
113\constfunc{bool}{IsMain}{\void}
114
6e6110ee 115Returns TRUE if the calling thread is the main application thread.
eaaa6a06 116
28d9589a
VZ
117\membersection{wxThread::IsPaused}\label{wxthreadispaused}
118
119\constfunc{bool}{IsPaused}{\void}
120
121Returns TRUE if the thread is paused.
122
123\membersection{wxThread::IsRunning}\label{wxthreadisrunning}
eaaa6a06 124
28d9589a 125\constfunc{bool}{IsRunning}{\void}
eaaa6a06 126
28d9589a
VZ
127Returns TRUE if the thread is running.
128
129\membersection{wxThread::Kill}\label{wxthreadkill}
130
131\func{wxThreadError}{Kill}{\void}
132
133Immediately terminates the target thread. {\bf This function is dangerous and should
134be used with extreme care (and not used at all whenever possible)!} The resources
135allocated to the thread will not be freed and the state of the C runtime library
136may become inconsistent. Use \helpref{Delete()}{wxthreaddelete} instead.
eaaa6a06
JS
137
138\membersection{wxThread::OnExit}\label{wxthreadonexit}
139
140\func{void}{OnExit}{\void}
141
28d9589a
VZ
142Called when the thread exits. This function is called in the context of the thread
143associated with the wxThread object, not in the context of the main thread.
eaaa6a06 144
e2a6f233
JS
145\membersection{wxThread::Run}\label{wxthreadrun}
146
147\func{wxThreadError}{Run}{\void}
148
149Runs the thread.
150
eaaa6a06
JS
151\membersection{wxThread::SetPriority}\label{wxthreadsetpriority}
152
153\func{void}{SetPriority}{\param{int}{ priority}}
154
155Sets the priority of the thread, between zero and 100. This must be set before the thread is created.
156
157The following priorities are already defined:
158
159\twocolwidtha{7cm}
160\begin{twocollist}\itemsep=0pt
e14dccff
KB
161\twocolitem{{\bf WXTHREAD\_MIN\_PRIORITY}}{0}
162\twocolitem{{\bf WXTHREAD\_DEFAULT\_PRIORITY}}{50}
163\twocolitem{{\bf WXTHREAD\_MAX\_PRIORITY}}{100}
eaaa6a06 164\end{twocollist}
28d9589a
VZ
165
166\membersection{wxThread::Sleep}\label{wxthreadsleep}
167
168\func{\void}{Sleep}{\param{unsigned long }{milliseconds}}
169
170Pauses the thread execution for the given amount of time.
171
172This function should be used instead of \helpref{wxSleep}{wxsleep} by all worker
173(i.e. all except the main one) threads.
174
175\membersection{wxThread::This}\label{wxthreadthis}
176
177\func{wxThread *}{This}{\void}
178
179Return the thread object for the calling thread. NULL is returned if the calling thread
180is the main (GUI) thread, but \helpref{IsMain}{wxthreadismain} should be used to test
181whether the thread is really the main one because NULL may also be returned for the thread
182not created with wxThread class. Generally speaking, the return value for such thread
183is undefined.
184
185\membersection{wxThread::Yield}\label{wxthreadyield}
186
187\func{\void}{Yield}{\void}
188
189Give the rest of the thread time slice to the system allowing the other threads to run.
190See also \helpref{Sleep()}{wxthreadsleep}.
e2a6f233 191