C++11多线程
tomorrow00hello
这个作者很懒,什么都没留下…
展开
-
C++11 多线程thread的休眠sleep_for chrono
使用C++11中的thread和chrono来实现休眠控制.this_thread::sleep_for(seconds(2));除了seconds外,还可使用std::chrono::nanosecondsstd::chrono::microsecondsstd::chrono::millisecondsstd::chrono::secondsstd::chrono::minutesstd::chrono::hours#include <chrono>#incl原创 2021-04-26 17:09:05 · 7538 阅读 · 0 评论 -
C++11 多线程thread使用
void CTask1::work(){ while (true) { cout<<"Task1"<<endl; std::this_thread::sleep_for(chrono::seconds(1)); }}//static void work1();void CTask1::work1(){ while (true) { cout<<"Task0 static"<<.原创 2021-04-16 15:50:41 · 191 阅读 · 0 评论 -
C++11多线程thread原子操作atomic
原子操作,就是多线程程序中“最小的且不可并行化的”操作。通常对一个共享资源的操作是原子操作的话,意味着多个线程访问该资源时,有且仅有唯一一个线程在对这个资源进行操作。C++11中支持的原子类型有常用的可以使用atomic类模板,通过类模板,可以任意定义出需要的原子类型std::atomic<T> t;//C++11atomic_int total{0};void func(){ for (int i = 0; i < 100000; i++)原创 2021-04-25 14:55:18 · 378 阅读 · 0 评论 -
C++11 多线程thread的join和detach函数使用
join waits for the thread to finish its execution (public member function) detach permits the thread to execute independently from the thread handle (public member function) 对创建线程的两种操作:等待/分离,join/detach1.join():主线程会阻塞,当子线程执行结束后,主线程才会继续...原创 2021-04-20 14:55:55 · 1144 阅读 · 0 评论