ONPOSIX
2.0
Main Page
Namespaces
Classes
Files
File List
File Members
ONPOSIX
OnPosix Library
Namespaces
Classes
Files
File List
include
AbstractDescriptorReader.hpp
AbstractThread.hpp
Assert.hpp
Buffer.hpp
DescriptorsMonitor.hpp
DgramSocketClientDescriptor.hpp
DgramSocketServerDescriptor.hpp
FifoDescriptor.hpp
FileDescriptor.hpp
Logger.hpp
Pipe.hpp
PosixCondition.hpp
PosixDescriptor.hpp
PosixMutex.hpp
PosixPrioritySharedQueue.hpp
PosixSharedQueue.hpp
Process.hpp
SimpleThread.hpp
StreamSocketClientDescriptor.hpp
StreamSocketServer.hpp
StreamSocketServerDescriptor.hpp
Time.hpp
src
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Enumerator
Friends
Macros
Pages
SimpleThread.hpp
Go to the documentation of this file.
1
/*
2
* SimpleThread.hpp
3
*
4
* Copyright (C) 2012 Evidence Srl - www.evidence.eu.com
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
15
*
16
* You should have received a copy of the GNU Library General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#ifndef SIMPLETHREAD_HPP_
22
#define SIMPLETHREAD_HPP_
23
24
#ifndef _GNU_SOURCE
25
#define _GNU_SOURCE
26
#endif
27
#include <pthread.h>
28
#include <features.h>
29
#include <vector>
30
31
#include "
AbstractThread.hpp
"
32
33
namespace
onposix {
34
35
/**
36
* \brief Class for simple thread invocation.
37
*
38
* This class is useful for creating threads that do not return any value.
39
* For more complex cases (e.g., return value), create your own thread by
40
* inheriting from class AbstractThread.
41
*
42
* Example of usage:
43
* \code
44
* void myfunction (void* arg);
45
*
46
* int main ()
47
* {
48
* int b;
49
* SimpleThread t (myfunction, (void*) b);
50
* t.start();
51
* t.waitForTermination();
52
* }
53
* \endcode
54
*/
55
class
SimpleThread
:
public
AbstractThread
{
56
57
void (*
handler_
)(
void
* p);
58
void
*
arg_
;
59
60
public
:
61
62
SimpleThread
(
void
(*handler)(
void
* p),
void
* arg):
63
handler_
(handler),
64
arg_
(arg) {}
65
virtual
~SimpleThread
(){}
66
67
/**
68
* \brief Method run on the new thread
69
*
70
* This method is run on the new thread once start()
71
* is invoked.
72
*/
73
inline
void
run
(){
74
handler_
(
arg_
);
75
}
76
};
77
78
}
/* onposix */
79
80
#endif
/* SIMPLETHREAD_HPP_ */
include
SimpleThread.hpp
Generated on Wed Apr 30 2014 15:27:24 for ONPOSIX by
1.8.1.2