-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (38 loc) · 1.4 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
46
47
48
49
50
51
#include <QCoreApplication>
#include <QThreadPool>
#include <iostream>
#include <thread>
#include <memory>
#include "messagequeue.h"
#include "messagequeuestd.h"
#include "messagequeuereader.h"
#include "messagequeuewriter.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QThreadPool::globalInstance()->setMaxThreadCount(8);
// qt-queue
//MessageQueue queue(256, 32, 224);
// std-queue
MessageQueueStd queue(256, 32, 224);
// writer in thread-pool
QThreadPool::globalInstance()->start(new MessageQueueWriter(queue));
// writer in std-thread
std::shared_ptr<MessageQueueWriter> writer = std::shared_ptr<MessageQueueWriter>(new MessageQueueWriter(queue));
std::thread standardWriterThread(&MessageQueueWriter::run, writer);
Q_UNUSED(standardWriterThread);
// reader in thread-pool
QThreadPool::globalInstance()->start(new MessageQueueReader(queue));
// reader in std-thread
std::shared_ptr<MessageQueueReader> reader = std::shared_ptr<MessageQueueReader>(new MessageQueueReader(queue));
std::thread standardReaderThread(&MessageQueueReader::run, reader);
Q_UNUSED(standardReaderThread);
queue.run();
char someNoneWhitespaceInput;
std::cin >> someNoneWhitespaceInput;
queue.stop();
standardReaderThread.join();
standardWriterThread.join();
QThreadPool::globalInstance()->waitForDone();
return 0;
}