当前位置:网站首页>线程的支持
线程的支持
2022-06-24 06:44:00 【雾散睛明】
线程的支持
c标准库:
c标准库没有线程的支持,需使用平台原生的函数:
windows:CreateThread
unix:pthread_create 其实线程是用进程模拟的。
c++标准库
operator= 只支持右值做参数,使用的move 原来的线程对象变为不可 joinable
get_id 获取线程id
joinable 检测线程是否可以等待,空的thread 对象是不可等待的。
join 等待线程执行完成。
detach 分离线程对象和线程,此时thread对象不代表线程,线程依旧继续执行。
swap 交换
native_handle 获取原生平台的线程句柄。
this_thread:
get_id 获取当前线程的id
yield 放弃当前线程的时间片 相当于sleep(0)
sleep_until:休眠
sleep_for:休眠
从上面发现thread从创建开始就开始执行了,没有start、stop、pause、resume等行为。
示例:
// thread example
#include <iostream> // std::cout
#include <thread> // std::thread
void foo()
{
// do stuff...
}
void bar(int x)
{
// do stuff...
}
int main()
{
std::thread first (foo); // spawn new thread that calls foo()
std::thread second (bar,0); // spawn new thread that calls bar(0)
std::cout << "main, foo and bar now execute concurrently...\n";
// synchronize threads:
first.join(); // pauses until first finishes
second.join(); // pauses until second finishes
std::cout << "foo and bar completed.\n";
return 0;
}
boost库:
详见:
<boost/thread/thread.hpp>
边栏推荐
- What is automated testing? What software projects are suitable for automated testing?
- Black box and white box models for interpretable AI
- Global and Chinese market of water massage column 2022-2028: Research Report on technology, participants, trends, market size and share
- How VPN works
- 相机标定(标定目的、原理)
- [OGeek2019]babyrop
- How to select a third-party software testing company? 2022 ranking of domestic software testing institutions
- Selector (>, ~, +, [])
- 阿里云全链路数据治理
- When MFC uses the console, the project path cannot have spaces or Chinese, otherwise an error will be reported. Lnk1342 fails to save the backup copy of the binary file to be edited, etc
猜你喜欢

get_started_3dsctf_2016
![[image segmentation] retinal vessel segmentation based on morphology with matlab code](/img/e3/0805df81a597346ea7c2d2da20ac96.png)
[image segmentation] retinal vessel segmentation based on morphology with matlab code

【008】表格数据逐行筛选,跳出for循环及跳过本次循环思路_#VBA
![[image feature extraction] image feature extraction based on pulse coupled neural network (PCNN) including Matlab source code](/img/b3/26cfa385aa357c3a7a77e9db47e94c.png)
[image feature extraction] image feature extraction based on pulse coupled neural network (PCNN) including Matlab source code

光照使用的简单总结
![[WUSTCTF2020]alison_ likes_ jojo](/img/a9/dcc6f524772cd0b8781289cbaef63f.png)
[WUSTCTF2020]alison_ likes_ jojo

MySQL - three tables (student, course, score) to query the name, number and score of students whose course is mathematics
![[image fusion] image fusion based on pseudo Wigner distribution (PWD) with matlab code](/img/e0/14cd7982fb3059fed235470d91126e.png)
[image fusion] image fusion based on pseudo Wigner distribution (PWD) with matlab code

使用SystemParametersInfo访问用户界面设置
![buuctf misc [UTCTF2020]docx](/img/e4/e160f704d6aa754e85056840e14bd2.png)
buuctf misc [UTCTF2020]docx
随机推荐
RDD basic knowledge points
Win10 build webservice
[pointnet] matlab simulation of 3D point cloud target classification and recognition based on pointnet
jarvisoj_ level2
LeetCode 207:课程表(拓扑排序判断是否成环)
Mysql database recovery case sharing
[image feature extraction] image feature extraction based on pulse coupled neural network (PCNN) including Matlab source code
Reppoints: Microsoft skillfully uses deformation convolution to generate point sets for target detection, full of creativity | iccv 2019
MFC multithreaded semaphore csemaphore critical area and mutually exclusive events
Climbing 10000 NASA pictures about Mars exploration, I found a secret
相機標定(標定目的、原理)
RDD的执行原理
Anaconda 中使用 You Get
C code writing specification
bjdctf_2020_babystack
UE常用控制臺命令
Detailed explanation of C language compilation, link and operation
What is a CC attack? How to judge whether a website is attacked by CC? How to defend against CC attacks?
后疫情时代下,家庭服务机器人行业才刚启航
【MySQL 使用秘籍】克隆数据表、保存查询数据至数据表以及创建临时表