当前位置:网站首页>Thread support
Thread support
2022-06-24 07:47:00 【Fog dispels eyesight】
Thread support
c Standard library :
c The standard library does not have thread support , Use platform native functions :
windows:CreateThread
unix:pthread_create In fact, threads are simulated by processes .
c++ Standard library
operator= Only right values are supported as parameters , The use of move The original thread object is changed to non joinable
get_id Get thread id
joinable Check whether the thread can wait , Empty thread Objects are not waiting .
join Wait for thread execution to complete .
detach Separate the thread object from the thread , here thread Object does not represent a thread , The thread continues to execute .
swap In exchange for
native_handle Get the thread handle of the native platform .
this_thread:
get_id Gets the current thread's id
yield Discard the time slice of the current thread amount to sleep(0)
sleep_until: Sleep
sleep_for: Sleep
Find... From above thread It has been executed since its creation , No, start、stop、pause、resume Such behavior .
Example :
// 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 library :
See :
<boost/thread/thread.hpp>
边栏推荐
猜你喜欢
随机推荐
Global and Chinese market of digital fryer 2022-2028: Research Report on technology, participants, trends, market size and share
行内元素、块元素、行内块元素
Thread blocking
[special session] SME growth plan - ECS special session
闲谈:3AC到底发生了什么?
How to realize multi protocol video capture and output in video surveillance system?
Baidu map, coordinate inversion, picking coordinate position
Pyhton crawls to Adu (Li Yifeng) Weibo comments
Global and Chinese market of water massage column 2022-2028: Research Report on technology, participants, trends, market size and share
.jar中没有主清单属性
随机数备注
智能指针备注
10 common malware detection and analysis platforms
Experience of Shenzhou computer
Black box and white box models for interpretable AI
Counter attack from outsourcing to big factories! Android has been developed for 5 years, and after a year of dormancy, it has tried to become an offer harvester. Tencent has a fixed salary of 20*15
How VPN works
A case of bouncing around the system firewall
Oracle-高级SQL限定查询
Continue to have a fever. Try the asynchronous operation of dart language. The efficiency is increased by 500%









