]> git.tdb.fi Git - libs/core.git/blob - source/core/thread.h
59e6e060ce4b77d2e0e69b45f245e6537ca3a70b
[libs/core.git] / source / core / thread.h
1 /* $Id$
2
3 This file is part of libmspcore
4 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_CORE_THREAD_H_
9 #define MSP_CORE_THREAD_H_
10
11 namespace Msp {
12
13 /**
14 Base class for threads.  To create a thread for some task, derive it from this
15 class and implement the main() function.  Note that threads are not
16 automatically started upon creation - you must manually call launch() instead.
17 This is to allow initializing variables of the derived class before the thread
18 is started.
19 */
20 class Thread
21 {
22 private:
23         struct Private;
24
25         Private *priv_;
26         bool launched_;
27
28 protected:
29         Thread();
30 private:
31         Thread(const Thread &);
32         Thread &operator=(const Thread &);
33 public:
34         virtual ~Thread();
35
36         void join();
37         void kill();
38 protected:
39         void launch();
40         virtual void main() = 0;
41 };
42
43 } // namespace Msp
44
45 #endif