forked from isliulin/TaoThread
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadUser.h
52 lines (50 loc) · 1.59 KB
/
ThreadUser.h
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
#pragma once
#include "ThreadPool.h"
#include "ThreadWorkerController.h"
#include <QDebug>
namespace TaoThread
{
class ThreadUser : public QObject
{
Q_OBJECT
public:
ThreadUser(int id)
{
m_id = id;
// ThreadPool::getInstance()->work(
// [id](){
// qWarning() << QThread::currentThreadId() << "do" << id;
// return true;
// },
// [this, id](bool result){
// qWarning() <<QThread::currentThreadId() << "work result:" << result << id;
// showId();
// });
ThreadController::getInstance()->work(
[id](){
int count = 0;
qWarning() << QThread::currentThreadId() << "do" << id;
while(1) {
qWarning() << QThread::currentThreadId() << "running" << id;
QThread::sleep(3);
count++;
if (count >= id) {
break;
}
}
return true;
},
[this, id](bool result){
qWarning() <<QThread::currentThreadId() << "work result:" << result << id;
showId();
}
);
}
void showId()
{
qWarning() << QThread::currentThreadId() << "showID " << m_id;
}
private:
int m_id;
};
}