This file is indexed.

/usr/include/zthread/Thread.h is in libzthread-dev 2.3.2-7ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
 * Copyright (c) 2005, Eric Crahen
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#ifndef __ZTTHREAD_H__
#define __ZTTHREAD_H__

#include "zthread/Cancelable.h"
#include "zthread/Priority.h"
#include "zthread/NonCopyable.h"
#include "zthread/Task.h"
#include "zthread/Waitable.h"

namespace ZThread {
  
  class ThreadImpl;
  
  /**
   * @class Thread
   * @author Eric Crahen <http://www.code-foo.com>
   * @date <2003-07-27T11:17:59-0400>
   * @version 2.3.0
   *
   *
   * @see Task
   * @see Executor
   *
   * <h2>Examples</h2>
   * - <a href="#ex1">Launching a task</a>
   * - <a href="#ex2">Waiting for a task</a>
   * - <a href="#ex3">Sharing a task</a>
   *
   * <h2><a name="ex1">Launching a task</a></h2>
   *
   * A thread is started simply by constructing a thread object and giving 
   * it a task to perform. The thread will continue to run its task, even 
   * after the Thread object used to launch the thread has gone out of scope.
   *
   * @code
   * #include "zthread/Thread.h"
   * #include <iostream>
   *
   * using namespace ZThread;
   *
   * class aRunnable : public Runnable {
   *
   *   void run() {
   *
   *     Thread::sleep(1000);
   *     std::cout << "Hello from another thread" << std::endl;
   *
   *   }
   *
   * };
   *
   * int main() {
   *
   *   try {
   *     
   *     // Implictly constructs a Task
   *     Thread t(new aRunnable);
   *
   *   } catch(Synchronization_Exception& e) { 
   *     std::cerr << e.what() << std::endl; 
   *   }
   *
   *   std::cout << "Hello from the main thread" << std::endl;
   *
   *   // Output:
   *
   *   // Hello from the main thread
   *   // Hello from another thread
   *
   *   return 0;
   *
   * }
   *
   * @endcode
   *
   * <h2><a name="ex2">Waiting for a task</a></h2>
   *
   * A user can exercise some simple synchronization by waiting for a thread
   * to complete running its task.
   *
   * @code
   * #include "zthread/Thread.h"
   * #include <iostream>
   *
   * using namespace ZThread;
   *
   * class aRunnable : public Runnable {
   * public:
   *
   *   void run() {
   *
   *     Thread::sleep(1000);
   *     std::cout << "Hello from another thread" << std::endl;
   *
   *   }
   *
   * };
   *
   * int main() {
   *
   *   try {
   *     
   *     // Implictly constructs a Task
   *     Thread t(new aRunnable);
   *     t.wait();
   *
   *   } catch(Synchronization_Exception& e) { 
   *     std::cerr << e.what() << std::endl; 
   *   }
   *
   *   std::cout << "Hello from the main thread" << std::endl;
   *
   *   // Output:
   *
   *   // Hello from another thread
   *   // Hello from the main thread
   *
   *   return 0;
   *
   * }
   *
   * @endcode
   *
   * <h2><a name="ex3">Sharing a task</a></h2>
   *
   * The same task can be shared by more than one thread. A Task is constructed
   * from a Runnable, and that Task object is copied by value and handed off to
   * each thread.
   *
   * @code
   * #include "zthread/Thread.h"
   * #include <iostream>
   *
   * using namespace ZThread;
   *
   * class aRunnable : public Runnable {
   *
   *   void run() {
   *
   *     Thread::sleep(1000);
   *     std::cout << "Hello from another thread" << std::endl;
   *
   *   }
   *
   * };
   *
   * int main() {
   *
   *   try {
   *     
   *     // Explictly constructs a Task
   *     Task task(new aRunnable);
   *
   *     // Two threads created to run the same Task
   *     Thread t1(task);
   *     Thread t2(task);
   *
   *   } catch(Synchronization_Exception& e) { 
   *     std::cerr << e.what() << std::endl; 
   *   }
   *
   *   std::cout << "Hello from the main thread" << std::endl;
   *
   *   // Output:
   *
   *   // Hello from the main thread
   *   // Hello from another thread
   *   // Hello from another thread
   *
   *   return 0;
   *
   * }
   *
   * @endcode
   */
  class ZTHREAD_API Thread 
    : public Cancelable, public Waitable, public NonCopyable {

    //! Delegate
    ThreadImpl* _impl;

  public:

    /**
     * Create a Thread that represents the current thread.
     * <em>Using the static members of Thread should be preferred over using this constructor</em>
     */
    Thread();

    /**
     * Create a Thread that spawns a new thread to run the given task.
     *
     * @param task Task to be run by a thread managed by this executor 
     * @param autoCancel flag to requestion automatic cancellation
     *
     * @post if the <i>autoCancel</i> flag was true, this thread will
     *       automatically be canceled when main() goes out of scope.
     */
    Thread(const Task&, bool autoCancel = false);

    //! Destroy the Thread
    ~Thread();

    //! Comparison operator
    bool operator==(const Thread& t) const;

    //! Comparison operator
    inline bool operator!=(const Thread& t) const {
      return !(*this == t);
    }

    /**
     * Wait for the thread represented by this object to complete its task.
     * The calling thread is blocked until the thread represented by this
     * object exits.
     *
     * @exception Deadlock_Exception thrown if thread attempts to join itself
     * @exception InvalidOp_Exception thrown if the thread cannot be joined
     * @exception Interrupted_Exception thrown if the joining thread has been interrupt()ed
     */
    void wait();
 
    /**
     * Wait for the thread represented by this object to complete its task.
     * The calling thread is blocked until the thread represented by this
     * object exits, or until the timeout expires.
     *
     * @param timeout maximum amount of time (milliseconds) this method 
     *        could block the calling thread.
     *
     * @return 
     *   - <em>true</em> if the thread task complete before <i>timeout</i> 
     *     milliseconds elapse.
     *   - <em>false</em> othewise.
     *
     * @exception Deadlock_Exception thrown if thread attempts to join itself
     * @exception InvalidOp_Exception thrown if the thread cannot be joined
     * @exception Interrupted_Exception thrown if the joining thread has been interrupt()ed
     */
    bool wait(unsigned long timeout);
 
    /**
     * Change the priority of this Thread. This will change the actual
     * priority of the thread when the OS supports it. 
     *
     * If there is no real priority support, it's simulated.
     *
     * @param p - new Priority
     */
    void setPriority(Priority p);

    /**
     * Get the priority of this Thread.
     *
     * @return Priority
     */
    Priority getPriority();

    /**
     * Interrupts this thread, setting the <i>interrupted</i> status of the thread.
     * This status is cleared by one of three methods. 
     *
     * If this thread is blocked when this method is called, the thread will
     * abort that blocking operation with an Interrupted_Exception.
     *
     *  - The first is by attempting an operation on a synchronization object that
     *    would normally block the calling thread; Instead of blocking the calling 
     *    the calling thread, the function that would normally block will thrown an
     *    Interrupted_Exception and clear the <i>interrupted</i> status of the thread.
     *
     *  - The second is by calling Thread::interrupted().
     * 
     *  - The third is by calling Thread::canceled().
     *
     * Threads already blocked by an operation on a synchronization object will abort
     * that operation with an Interrupted_Exception, clearing the threads <i>interrupted</i>
     * status as in the first case described above.
     *
     * Interrupting a thread that is no longer running will have no effect.
     *
     * @return 
     *   - <em>true</em> if the thread was interrupted while not blocked by a wait
     *     on a synchronization object.
     *   - <em>false</em> othewise.
     */
    bool interrupt();

    /**
     * Tests whether the current Thread has been interrupt()ed, clearing
     * its interruption status.
     *
     * @return 
     *   - <em>true</em> if the Thread was interrupted.
     *   - <em>false</em> otherwise.
     *
     * @post The <i>interrupted</i> status of the current thread will be cleared, 
     *       allowing it to perform a blocking operation on a synchronization
     *       object without throwing an exception.
     */
    static bool interrupted();

    /**
     * Tests whether the current Thread has been canceled, and clears the
     * interrupted status.
     *
     * @return bool true only if the Thread::cancel() has been invoked.
     */
    static bool canceled();

    /**
     * Tests whether this thread has been canceled. If called from the context
     * of this thread, the interrupted status is cleared.
     *
     * @return 
     *   - <em>true</em> if the Thread was canceled.
     *   - <em>false</em> otherwise.
     * 
     * @see Cancelable::isCanceled()
     */
    virtual bool isCanceled();

    /**
     * Interrupt and cancel this thread in a single operation. The thread will 
     * return <em>true</em> whenever its cancelation status is tested in the future.
     *
     * @exception InvalidOp_Exception thrown if a thread attempts to cancel itself
     *
     * @see Thread::interrupt()
     * @see Cancelable::cancel()
     */
    virtual void cancel();

    /**
     * Put the currently executing thread to sleep for a given amount of
     * time.
     *
     * @param timeout maximum amount of time (milliseconds) this method could block
     *
     * @exception Interrupted_Exception thrown if the threads sleep is interrupted
     *            before <i>timeout</i> milliseconds expire.
     */
    static void sleep(unsigned long timeout);

    /**
     * Cause the currently executing thread to yield, allowing the scheduler
     * to assign some execution time to another thread.
     */
    static void yield();


  }; /* Thread */


} // namespace ZThread

#endif // __ZTTHREAD_H__