Search code examples
c++visual-studiosemaphorebinary-semaphore

Unable to use std:: counting_semaphore in Visual Studio 2019 and 2022


So I am trying to use counting_semaphore in visual studio 2019 and 2022 but all I get is " std has no member counting_semaphore".

I tried it in visual studio 2019 after adding the clang 11 in individual components but I still get the same error. Then I was like ok it doesn't support C++20. So I thought maybe that's why it doesn't work.

Then I saw Vs2022 Preview supports C++20. So I installed it, included and still I cant do "std::counting_semaphore<5> slots(5);" as it says std doesn't have a member called counting semaphore.

I also installed clang12 in the individual components in 2022 preview installer and still I didn't get it to work.

I am not sure what I am doing wrong.

I see examples online:

https://www.modernescpp.com/index.php/semaphores-in-c-20 https://en.cppreference.com/w/cpp/thread/counting_semaphore

telling how to use it, but when I put the code in vs it just doesn't work.

I can do "view code" on #include and it shows implementation of counting_semaphore and yet I cant use it!!!

Kindly someone please clarify what I am doing wrong!!!

enter image description here

enter image description here

enter image description here


Solution

  • Whether you have set the c++ language standard?

    Property -> General -> C++ Language Standard -> /std: c++ latest

    enter image description here

    I could build successfully in visual studio 2022 preview 17.0.0 preview 2.0.

    enter image description here

    And I could also build successfully in visual studio 2019.

    enter image description here