当前位置:网站首页>STD:: thread combine avec des objets de classe
STD:: thread combine avec des objets de classe
2022-07-22 10:20:00 【Make It Simple 888】
Classe ordinaire
#include <iostream>
#include <thread>
#include <functional>
using namespace std;
struct Task
{
int i = 100;
void do_job(void)
{
std::cout<< "Hello Task::f ! i=" << i << std::endl;
}
};
typedef function<void()> fun;
int main()
{
Task task;
auto worker = std::bind(&Task::do_job, task);
thread t(worker);
t.join();
std::cout << "Hello World!\n";
}
Classe non ordinaire
Classes dont la reproduction est interdite
#include <iostream>
#include <thread>
#include <mutex>
#include <functional>
using namespace std;
struct Task
{
int i = 100;
void do_job(void)
{
std::cout<< "Hello Task::f ! i=" << i << std::endl;
}
//Ne plus utiliserbindSyntaxe
static void run(void* obj_this)
{
static_cast<Task*>(obj_this)->do_job();
}
mutex m_mutex;// Ce membre interdit la copie
};
typedef function<void()> fun;
int main()
{
Task task;
auto worker = std::bind(&Task::run, &task);
thread t(worker);
t.join();
std::cout << "Hello World!\n";
}
边栏推荐
- How many months did you write your first SCI? (Part II)
- 集合(Properties)
- 谷歌 Chrome 浏览器将支持在任意网页上做笔记,还能多设备同步
- Energy principle and variational method note 05: examples of natural boundary conditions
- Notes on energy principle and variational method 07: variational problem of multiple self variable functions + variational method of conditional extreme value problem + thinking in Chapter 1
- 能量原理与变分法笔记08: 虚功原理的推导
- 基于卡尔曼滤波的微电网调度(Matlab代码实现)
- Find all letter ectopic words in the string
- Parent element visibility:hidden; Set visibility:visible for child elements. Are child elements displayed
- Rhcsa compression also includes decompression, tar archive command, file upload and download, variables in sehll, command alias, and command history
猜你喜欢
10大主流压力/负载/性能测试工具推荐
Unity Scrollview scroll to the specified position
RHCSA 简单命令的使用(ls、date、timedatectl、file、stat),文件类型
能量原理与变分法笔记09: 虚功原理的例子
Unity C: use this keyword to expand class functions
openEuler志高远,开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛即将开幕
能量原理与变分法笔记03:证明两点之间直线最短
day02-2
输入密码才可以浏览网页的PHP源码
Energy principle and variational method note 04: natural boundary conditions
随机推荐
Online XML to CSV tool
百度飞桨EasyDL X 韦士肯:看轴承质检如何装上“AI之眼”
Suppose overflow:hidden is set in the div, and there is a select box in it. What if it is covered?
C# 与CAD二次开发,20220721随笔代码
Microgrid scheduling based on Kalman filter (matlab code implementation)
Equal principal increasing repayment / equal principal decreasing mortgage repayment calculator
背会这些面试题,任何技术面能成功一半
Qt Creator 8发布
Parent element visibility:hidden; Set visibility:visible for child elements. Are child elements displayed
Start, close and view MySQL service (Linux)
HCIP(10)
能量原理与变分法笔记10:虚位移原理
能量原理与变分法笔记01:三种分析方法的简单介绍
银河证券vip链接开户安全吗,佣金最低多少的?
To solve the pain points of API development, which is better, API post or API box?
智能手机天线调谐
Unity Scrollview scroll to the specified position
HCIP(9)
上门预约程序公众号模块 完美版
List collection