/usr/include/wibble/sys/thread.h is in libwibble-dev 1.1-1.
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 | /* -*- C++ -*-
* OO encapsulation of Posix threads
*
* Copyright (C) 2003--2013 Enrico Zini <enrico@debian.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef WIBBLE_SYS_THREAD_H
#define WIBBLE_SYS_THREAD_H
#include <wibble/sys/macros.h>
#include <wibble/exception.h>
#ifdef POSIX
#include <pthread.h>
#include <unistd.h>
#endif
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#endif
#include <signal.h>
namespace wibble {
namespace sys {
/// Portable version of sleep
void sleep( int secs );
/// Portable version of usleep
void usleep( int usecs );
/**
* Encapsulates a thread
*
* FIXME: C++ resource management and thread cancellation
* C++ uses the "resource allocation is instantiation" way of managing
* resources: when a function exits, either by terminating or because
* an exception has been raised, destructors are called.
*
* However, when a thread is canceled, the flow of control is
* interrupted and no exceptions are thrown. Cleanup should be
* performed by registering cleanup functions, but a cleanup function
* can't usefully throw exceptions nor call destructors.
* At the moment, I don't know what to do to correctly release
* resources on thread cancellation. I'm waiting for new ideas.
*
* The current way out is not to use cancelation, but explicitly set
* some boolean exit condition:
*
* \code
* class MyThread
* {
* bool interrupted;
* void* main()
* {
* // do things
* if (interrupted)
* throw MyInterruptedException();
* // do things
* while (!interrupted)
* {
* // do things
* }
* }
* MyThread() : interrupted(false) {}
* }
* \endcode
*/
class Thread
{
protected:
#ifdef POSIX
pthread_t thread;
#endif
#ifdef _WIN32
void *_result;
unsigned int thread;
HANDLE hThread;
#endif
/**
* Short tag describing this thread, used in error messages and
* identification
*/
virtual const char* threadTag() { return "generic"; }
/** Main thread function, executed in the new thread after creation.
* When main() exits, the new thread ends and main() result will be the
* thread exit result
*/
virtual void* main() = 0;
/// Callback function used to start the thread
#ifdef POSIX
static void* Starter(void* parm);
#endif
#ifdef _WIN32
static unsigned __stdcall Starter(void* parm);
#endif
void testcancel();
public:
virtual ~Thread() {}
/// Start the thread
void start();
/// Start the thread in the detached state
void startDetached();
/// Join the thread
void* join();
/// Put the thread in the detached state
void detach();
/// Send a cancellation request to the thread
void cancel();
/// Sent a signal to the thread
void kill(int signal);
};
}
}
// vim:set ts=4 sw=4:
#endif
|