当前位置:网站首页>线程的支持
线程的支持
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>
边栏推荐
- RDD的执行原理
- UE common console commands
- New ways to play web security [6] preventing repeated use of graphic verification codes
- [signal recognition] signal modulation classification based on deep learning CNN with matlab code
- Tencent cloud security and privacy computing has passed the evaluation of the ICT Institute and obtained national recognition
- Extend ado Net to realize object-oriented CRUD (.Net core/framework)
- Reconfiguration of nebula integration testing framework based on BDD theory (Part 2)
- What challenges does the video streaming media platform face in transmitting HD video?
- C code writing specification
- [TS] function type
猜你喜欢

jarvisoj_ level2

Session & cookie details

get_started_3dsctf_2016

How can win11 set the CPU performance to be fully turned on? How does win11cpu set high performance mode?
![[vulhub shooting range]] ZABBIX SQL injection (cve-2016-10134) vulnerability recurrence](/img/c5/f548223666d7379a7d4aaed2953587.png)
[vulhub shooting range]] ZABBIX SQL injection (cve-2016-10134) vulnerability recurrence

使用SystemParametersInfo访问用户界面设置

Étalonnage de la caméra (objectif et principe d'étalonnage)

More than 60 million shovel excrement officials, can they hold a spring of domestic staple food?
![[WUSTCTF2020]alison_ likes_ jojo](/img/a9/dcc6f524772cd0b8781289cbaef63f.png)
[WUSTCTF2020]alison_ likes_ jojo
![[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
随机推荐
《canvas》之第2章 直线图形
Win11 points how to divide disks? How to divide disks in win11 system?
使用SystemParametersInfo访问用户界面设置
L2tp/ipsec one click installation script
C# Lambda
Global and Chinese market of inline drip irrigation 2022-2028: Research Report on technology, participants, trends, market size and share
How to turn on win11 notebook power saving mode? How to open win11 computer power saving mode
[image fusion] image fusion based on pseudo Wigner distribution (PWD) with matlab code
图形技术之坐标转换
Deploy L2TP in VPN (medium)
[tips] use the deep learning toolbox of MATLAB deepnetworkdesigner to quickly design
[frame rate doubling] development and implementation of FPGA based video frame rate doubling system Verilog
相机标定(标定目的、原理)
[equalizer] bit error rate performance comparison simulation of LS equalizer, def equalizer and LMMSE equalizer
爬虫基础B1——Scrapy(B站学习笔记)
【008】表格数据逐行筛选,跳出for循环及跳过本次循环思路_#VBA
Accessing user interface settings using systemparametersinfo
Face pincher: a hot meta universe stylist
Global and Chinese market of anion sanitary napkins 2022-2028: Research Report on technology, participants, trends, market size and share
【MySQL 使用秘籍】克隆数据表、保存查询数据至数据表以及创建临时表