summaryrefslogtreecommitdiffstats
path: root/doc/html/tqthread.html
blob: f09d9060157da57ffe9f78b70eeab77e5c87eeb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/tqthread.cpp:52 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQThread Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQThread Class Reference</h1>

<p>The TQThread class provides platform-independent threads.
<a href="#details">More...</a>
<p>All the functions in this class are <a href="threads.html#threadsafe">thread-safe</a> when TQt is built with thread support.</p>
<p><tt>#include &lt;<a href="tqthread-h.html">tqthread.h</a>&gt;</tt>
<p>Inherits <a href="tqt.html">TQt</a>.
<p><a href="tqthread-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#TQThread"><b>TQThread</b></a> ( unsigned&nbsp;int&nbsp;stackSize = 0 )</li>
<li class=fn>virtual <a href="#~TQThread"><b>~TQThread</b></a> ()</li>
<li class=fn>bool <a href="#wait"><b>wait</b></a> ( unsigned&nbsp;long&nbsp;time = ULONG_MAX )</li>
<li class=fn>enum <a href="#Priority-enum"><b>Priority</b></a> { IdlePriority, LowestPriority, LowPriority, NormalPriority, HighPriority, HighestPriority, TimeCriticalPriority, InheritPriority }</li>
<li class=fn>void <a href="#start"><b>start</b></a> ( Priority&nbsp;priority = InheritPriority )</li>
<li class=fn>void <a href="#terminate"><b>terminate</b></a> ()</li>
<li class=fn>bool <a href="#finished"><b>finished</b></a> () const</li>
<li class=fn>bool <a href="#running"><b>running</b></a> () const</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>TQt::HANDLE <a href="#currentThread"><b>currentThread</b></a> ()</li>
<li class=fn>void <a href="#exit"><b>exit</b></a> ()</li>
</ul>
<h2>Protected Members</h2>
<ul>
<li class=fn>virtual void <a href="#run"><b>run</b></a> () = 0</li>
</ul>
<h2>Static Protected Members</h2>
<ul>
<li class=fn>void <a href="#sleep"><b>sleep</b></a> ( unsigned&nbsp;long&nbsp;secs )</li>
<li class=fn>void <a href="#msleep"><b>msleep</b></a> ( unsigned&nbsp;long&nbsp;msecs )</li>
<li class=fn>void <a href="#usleep"><b>usleep</b></a> ( unsigned&nbsp;long&nbsp;usecs )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>



The TQThread class provides platform-independent threads.
<p> 

<p> A TQThread represents a separate thread of control within the
program; it shares data with all the other threads within the
process but executes independently in the way that a separate
program does on a multitasking operating system. Instead of
starting in main(), TQThreads begin executing in <a href="#run">run</a>(). You inherit
run() to include your code. For example:
<p> <pre>
    class MyThread : public TQThread {

    public:

        virtual void run();

    };

    void MyThread::<a href="#run">run</a>()
    {
        for( int count = 0; count &lt; 20; count++ ) {
            <a href="#sleep">sleep</a>( 1 );
            <a href="ntqapplication.html#qDebug">tqDebug</a>( "Ping!" );
        }
    }

    int main()
    {
        MyThread a;
        MyThread b;
        a.<a href="#start">start</a>();
        b.<a href="#start">start</a>();
        a.<a href="#wait">wait</a>();
        b.<a href="#wait">wait</a>();
    }
    </pre>
 
<p> This will start two threads, each of which writes Ping! 20 times
to the screen and exits. The <a href="#wait">wait</a>() calls at the end of main() are
necessary because exiting main() ends the program, unceremoniously
killing all other threads. Each MyThread stops executing when it
reaches the end of MyThread::run(), just as an application does
when it leaves main().
<p> <p>See also <a href="threads.html">Thread Support in TQt</a>, <a href="environment.html">Environment Classes</a>, and <a href="thread.html">Threading</a>.

<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="Priority-enum"></a>TQThread::Priority</h3>

<p> This enum type indicates how the operating system should schedule
newly created threads.
<ul>
<li><tt>TQThread::IdlePriority</tt> - scheduled only when no other threads are
running.
<li><tt>TQThread::LowestPriority</tt> - scheduled less often than LowPriority.
<li><tt>TQThread::LowPriority</tt> - scheduled less often than NormalPriority.
<li><tt>TQThread::NormalPriority</tt> - the default priority of the operating
system.
<li><tt>TQThread::HighPriority</tt> - scheduled more often than NormalPriority.
<li><tt>TQThread::HighestPriority</tt> - scheduled more often then HighPriority.
<li><tt>TQThread::TimeCriticalPriority</tt> - scheduled as often as possible.
<li><tt>TQThread::InheritPriority</tt> - use the same priority as the creating
thread.  This is the default.
</ul>
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQThread"></a>TQThread::TQThread ( unsigned&nbsp;int&nbsp;stackSize = 0 )
</h3>
Constructs a new thread. The thread does not begin executing until
<a href="#start">start</a>() is called.
<p> If <em>stackSize</em> is greater than zero, the maximum stack size is
set to <em>stackSize</em> bytes, otherwise the maximum stack size is
automatically determined by the operating system.
<p> <b>Warning:</b> Most operating systems place minimum and maximum limits
on thread stack sizes. The thread will fail to start if the stack
size is outside these limits.

<h3 class=fn><a name="~TQThread"></a>TQThread::~TQThread ()<tt> [virtual]</tt>
</h3>
TQThread destructor.
<p> Note that deleting a TQThread object will not stop the execution of
the thread it represents. Deleting a running TQThread (i.e.
<a href="#finished">finished</a>() returns FALSE) will probably result in a program crash.
You can <a href="#wait">wait</a>() on a thread to make sure that it has finished.

<h3 class=fn>TQt::HANDLE <a name="currentThread"></a>TQThread::currentThread ()<tt> [static]</tt>
</h3>
This returns the thread handle of the currently executing thread.
<p> <b>Warning:</b> The handle returned by this function is used for internal
purposes and should <em>not</em> be used in any application code. On
Windows, the returned value is a pseudo handle for the current
thread, and it cannot be used for numerical comparison.

<h3 class=fn>void <a name="exit"></a>TQThread::exit ()<tt> [static]</tt>
</h3>
Ends the execution of the calling thread and wakes up any threads
waiting for its termination.

<h3 class=fn>bool <a name="finished"></a>TQThread::finished () const
</h3>
Returns TRUE if the thread is finished; otherwise returns FALSE.

<h3 class=fn>void <a name="msleep"></a>TQThread::msleep ( unsigned&nbsp;long&nbsp;msecs )<tt> [static protected]</tt>
</h3>
System independent sleep. This causes the current thread to sleep
for <em>msecs</em> milliseconds

<h3 class=fn>void <a name="run"></a>TQThread::run ()<tt> [pure virtual protected]</tt>
</h3>

<p> This method is pure virtual, and must be implemented in derived
classes in order to do useful work. Returning from this method
will end the execution of the thread.
<p> <p>See also <a href="#wait">wait</a>().

<h3 class=fn>bool <a name="running"></a>TQThread::running () const
</h3>
Returns TRUE if the thread is running; otherwise returns FALSE.

<h3 class=fn>void <a name="sleep"></a>TQThread::sleep ( unsigned&nbsp;long&nbsp;secs )<tt> [static protected]</tt>
</h3>
System independent sleep. This causes the current thread to sleep
for <em>secs</em> seconds.

<h3 class=fn>void <a name="start"></a>TQThread::start ( <a href="tqthread.html#Priority-enum">Priority</a>&nbsp;priority = InheritPriority )
</h3>
Begins execution of the thread by calling <a href="#run">run</a>(), which should be
reimplemented in a TQThread subclass to contain your code.  The
operating system will schedule the thread according to the <em>priority</em> argument.
<p> If you try to start a thread that is already running, this
function will wait until the the thread has finished and then
restart the thread.
<p> <p>See also <a href="#Priority-enum">Priority</a>.

<h3 class=fn>void <a name="terminate"></a>TQThread::terminate ()
</h3>
This function terminates the execution of the thread. The thread
may or may not be terminated immediately, depending on the
operating system's scheduling policies. Use <a href="#wait">TQThread::wait</a>()
after <a href="#terminate">terminate</a>() for synchronous termination.
<p> When the thread is terminated, all threads waiting for the
the thread to finish will be woken up.
<p> <b>Warning:</b> This function is dangerous, and its use is discouraged.
The thread can be terminated at any point in its code path.  Threads
can be terminated while modifying data.  There is no chance for
the thread to cleanup after itself, unlock any held mutexes, etc.
In short, use this function only if <em>absolutely</em> necessary.

<h3 class=fn>void <a name="usleep"></a>TQThread::usleep ( unsigned&nbsp;long&nbsp;usecs )<tt> [static protected]</tt>
</h3>
System independent sleep. This causes the current thread to sleep
for <em>usecs</em> microseconds

<h3 class=fn>bool <a name="wait"></a>TQThread::wait ( unsigned&nbsp;long&nbsp;time = ULONG_MAX )
</h3>
A thread calling this function will block until either of these
conditions is met:
<p> <ul>
<li> The thread associated with this TQThread object has finished
execution (i.e. when it returns from <a href="#run">run</a>()). This function
will return TRUE if the thread has finished. It also returns
TRUE if the thread has not been started yet.
<li> <em>time</em> milliseconds has elapsed. If <em>time</em> is ULONG_MAX (the
default), then the wait will never timeout (the thread must
return from <a href="#run">run</a>()). This function will return FALSE if the
wait timed out.
</ul>
<p> This provides similar functionality to the POSIX <tt>pthread_join()</tt> function.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>