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