forked from L1w-Y/muduo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.h
More file actions
35 lines (30 loc) · 749 Bytes
/
Copy pathThread.h
File metadata and controls
35 lines (30 loc) · 749 Bytes
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
#pragma once
#include"noncopyable.h"
#include<functional>
#include<thread>
#include<memory>
#include<unistd.h>
#include <atomic>
#include <cstdint>
class Thread : noncopyable
{
public:
using ThreadFunc = std::function<void()>;
explicit Thread(ThreadFunc,const std::string& name=std::string());
~Thread();
void start();
void join();
bool started()const {return started_;}
pid_t tid()const {return tid_;}
const std::string& name(){return name_;}
static int numCreated(){return numCreated_;}
private:
void setDefaultName();
bool started_;
bool joined_;
std::shared_ptr<std::thread> thread_;
pid_t tid_;
ThreadFunc func_;
std::string name_;
static std::atomic<int> numCreated_;
};