I have seen a few contradictory posts in SO about std::thread in Visual Studio:
C++11 std::threads vs posix threads
C++11 std::thread vs windows CreateThread
std::thread Visual Studio 2012 Warning
Visual Studio 2013 std::thread
According to the reference, there is no limit.
I tried the following code on visual studio 2017
#include "stdafx.h"
#include <iostream>
#include <thread>
#include <chrono>
void foo()
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
int main()
{
std::thread t;
std::cout << "before starting, joinable: " << std::boolalpha << t.joinable()
<< '\n';
t = std::thread(foo);
std::cout << "after starting, joinable: " << t.joinable()
<< '\n';
t.join();
std::cout << "after joining, joinable: " << t.joinable()
<< '\n';
}
There was no error.
I also set the compiler and linker option -pthread and received a few warnings with code D9002 and LNK4044:
1>---- Rebuild All started: Project: ConsoleApplication2, Configuration: Debug Win32 ----
1>cl : Command line warning D9002: ignoring unknown option '-pthread'
1>stdafx.cpp
1>cl : Command line warning D9002: ignoring unknown option '-pthread'
1>ConsoleApplication2.cpp
1>LINK : warning LNK4044: unrecognized option '/pthread'; ignored
1>ConsoleApplication2.vcxproj -> D:\ConsoleApplication2\Debug\ConsoleApplication2.exe
1>Done building project "ConsoleApplication2.vcxproj".
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Can I conclude that Visual studio 2017 supports std::thread and it requires no additional compiler and linker option to use them?
Aucun commentaire:
Enregistrer un commentaire