相关疑难解决方法(0)

std :: async有什么问题?

在C++ And Beyond 的这篇剪辑的开头附近,我听到了一些关于问题的内容std::async.我有两个问题:

  1. 对于初级开发人员,是否有一套规则用于做什么以及在使用时要避免什么std::async?

  2. 这个视频有什么问题?它们与本文有关吗?

c++ multithreading c++11 stdasync

18
推荐指数
2
解决办法
4087
查看次数

C++ program unexpectedly blocks / throws

I'm learning about mutexes in C++ and have a problem with the following code (taken from N. Josuttis' "The C++ Standard Library").

I don't understand why it blocks / throws unless I add this_thread::sleep_for in the main thread (then it doesn't block and all three calls are carried out).

The compiler is cl.exe used from the command line.

#include <future>
#include <mutex>
#include <iostream>
#include <string>
#include <thread>
#include <chrono>

std::mutex printMutex;

void print(const std::string& s)
{
    std::lock_guard<std::mutex> lg(printMutex);

    for …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading c++11

9
推荐指数
1
解决办法
473
查看次数

标签 统计

c++ ×2

c++11 ×2

multithreading ×2

stdasync ×1