当前位置:网站首页>线程的支持
线程的支持
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>
边栏推荐
- [从零开始学习FPGA编程-42]:视野篇 - 后摩尔时代”芯片设计的技术演进-1-现状
- 选择器(>,~,+,[])
- 2.1.1 QML grammar foundation I
- 希尔伯特-黄变换
- bjdctf_2020_babystack
- C code writing specification
- How to open the soft keyboard in the computer, and how to open the soft keyboard in win10
- [wustctf2020] climb
- Virtual machine security disaster recovery construction
- Phonics
猜你喜欢
![选择器(>,~,+,[])](/img/7e/2becfcf7a7b2e743772deee5916caf.png)
选择器(>,~,+,[])

Win10 build webservice

How can win11 set the CPU performance to be fully turned on? How does win11cpu set high performance mode?
![[WUSTCTF2020]alison_ likes_ jojo](/img/a9/dcc6f524772cd0b8781289cbaef63f.png)
[WUSTCTF2020]alison_ likes_ jojo
![[OGeek2019]babyrop](/img/74/5f93dcee9ea5a562a7fba5c17aab76.png)
[OGeek2019]babyrop
![[Proteus] Arduino uno + ds1307+lcd1602 time display](/img/96/d8c1cacc8a633c679b1a58a1eb8cb9.png)
[Proteus] Arduino uno + ds1307+lcd1602 time display
╯︵ ┻━┻](/img/26/6986a8ae6c00eb2431a082dc0ff978.png)
[DDCTF2018](╯°□°)╯︵ ┻━┻
![[WUSTCTF2020]alison_likes_jojo](/img/a9/dcc6f524772cd0b8781289cbaef63f.png)
[WUSTCTF2020]alison_likes_jojo

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
![buuctf misc [UTCTF2020]docx](/img/e4/e160f704d6aa754e85056840e14bd2.png)
buuctf misc [UTCTF2020]docx
随机推荐
How to realize high stability and high concurrency of live video streaming transmission and viewing?
Wechat cloud hosting hot issues Q & A
Tidb operator source code reading (IV) control cycle of components
Global and Chinese market of offshore furnaces 2022-2028: Research Report on technology, participants, trends, market size and share
get_ started_ 3dsctf_ two thousand and sixteen
Common coding and encryption in penetration testing
How to select a third-party software testing company? 2022 ranking of domestic software testing institutions
A summary of the posture of bouncing and forwarding around the firewall
MaxCompute远程连接,上传、下载数据文件操作
第三方软件测试公司如何选择?2022国内软件测试机构排名
UTC、GMT、CST
屏幕截图推荐—Snipaste
atguigu----15-内置指令
Mysql database recovery case sharing
Virtual machine security disaster recovery construction
Black box and white box models for interpretable AI
MySQL case: analysis of full-text indexing
[Lua language from bronze to king] Part 2: development environment construction +3 editor usage examples
[Proteus] Arduino uno + ds1307+lcd1602 time display
Étalonnage de la caméra (objectif et principe d'étalonnage)