2

I'm learning multithreading now and want to use std::scoped_lock, but Microsoft Visual Studio 2017 shows error message saying

namespace "std" has no member "scoped_lock"

I made sure that I'm using C++17 by right click project name -> Properties -> C/C++ -> Language -> C++ Language Standard -> /std:c++17. I searched google, but couldn't find any solution.

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

void PrintMessage(const std::string& message)
{
    static std::mutex sMutex;
    std::scoped_lock<std::mutex> lock(sMutex);
    std::cout << message << std::endl;
}

I want to use std::scoped_lock without error message.

David
  • 81
  • 2
  • 4

0 Answers0