indexthread
Defined in header file: thread.hh
Description
Example
class mythread : public thread {
public:
mythread() { }
virtual void run() {
int i = 0;
while (true) {
cout << ++i << endl;
sleep(1);
}
}
};
int main(int argc, char** argv) {
mythread t;
t.start();
sleep(5);
}
output:
1
2
3
4
5
Public base classes
Constructors
| Constructor |
Description |
| thread() |
Constructor. |
Members
| Types |
Description |
| Methods |
|
bool
start(bool detached = true) |
Starts the thread and returns immediately to the caller. If detached is set to true the state of the thread is set to PTHREAD_CREATE_DETACHED otherwise to PTHREAD_CREATE_JOINABLE. Returns true on succhess. |
|
virtual void
run()
= 0
|
Abstract method that is started by start(). |
|
bool
finished() |
Checks whether the thread has been finished. |
|
bool
cancel() |
Cancels the thread. |
|
bool
join() |
Joins the thread. To join a thread it must not have been detached. At most one thread can wait for the termination of a given thread. |
|
void
set_exit_callback(void(*)(void*)
)
|
Sets a callback method which is called as soon as the thread has been finished. |
index