-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.cpp
46 lines (34 loc) · 1.13 KB
/
main.cpp
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
#include "WorkerThread.h"
#include "Fault.h"
#include <iostream>
// @see https://github.com/endurodave/StdWorkerThread
// David Lafreniere
using namespace std;
// Worker thread instances
WorkerThread workerThread1("WorkerThread1");
WorkerThread workerThread2("WorkerThread2");
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int main(void)
{
// Create worker threads
workerThread1.CreateThread();
workerThread2.CreateThread();
// Create message to send to worker thread 1
std::shared_ptr<UserData> userData1(new UserData());
userData1->msg = "Hello world";
userData1->year = 2017;
// Post the message to worker thread 1
workerThread1.PostMsg(userData1);
// Create message to send to worker thread 2
std::shared_ptr<UserData> userData2(new UserData());
userData2->msg = "Goodbye world";
userData2->year = 2017;
// Post the message to worker thread 2
workerThread2.PostMsg(userData2);
std::this_thread::sleep_for(std::chrono::seconds(1));
workerThread1.ExitThread();
workerThread2.ExitThread();
return 0;
}