File: ThreadBase.cpp

package info (click to toggle)
librepfunc 1.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: cpp: 1,601; makefile: 270
file content (57 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (2)
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
/*******************************************************************************
 * librepfunc - a collection of common functions, classes and tools.
 * See the README file for copyright information and how to reach the author.
 ******************************************************************************/
#include <string>    // std::string
#include <iostream>  // std::cout
#include <repfunc.h> // include this library



class cWorker : public ThreadBase {
protected:
  void Action(void);
public:
  cWorker(void);
  ~cWorker();
};

cWorker::cWorker(void) {
  // add something to initialize here.
}

cWorker::~cWorker() {
  // clean up after yourselves
}

void cWorker::Action(void) {
  // some child thread which does work beside main thread.
  size_t n = 0;
  while(Running()) {
     std::cout << "worker thread: " << IntToStr(n++) << std::endl;
     mSleep(100);
     }
}




int main() {
  std::cout << "main thread line " << __LINE__ << std::endl;

  cWorker* child_thread = new cWorker;
  // start the thread.
  child_thread->Start();

  Sleep(5);

  // stop the thread
  child_thread->Cancel();

  // wait until thread really finished.
  child_thread->Join();

  std::cout << "main thread line " << __LINE__ << std::endl;

  return 0;
}