Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<thread>:std::this_thread::sleep_for won't return if change the time back #3605

Closed
UMU618 opened this issue Mar 30, 2023 · 2 comments
Closed

Comments

@UMU618
Copy link

UMU618 commented Mar 30, 2023

Describe the bug
https://developercommunity.visualstudio.com/t/STL-std::this_thread::sleep_for-wont/10327605?port=1025&fsid=e785caac-6a7e-499b-87f5-e731ecbca870

std::this_thread::sleep_for won't return if change the time back

Command-line test case

#include <iostream>

#define BOOST_ALL_DYN_LINK 1
#include <boost/chrono.hpp>
#include <boost/thread.hpp>

int main() {
  std::thread boost{[]() {
    for (int i = 0; i < 100; ++i) {
      boost::this_thread::sleep_for(boost::chrono::seconds(1));
      std::cout << "boost: " << i << '\n';
    }
  }};

  std::thread stl{[]() {
    for (int i = 0; i < 100; ++i) {
      std::this_thread::sleep_for(std::chrono::seconds(1));
      std::cout << "STL: " << i << '\n';
    }
  }};

  boost.join();
  stl.join();
}

Expected behavior
Won't block.

STL version
Microsoft Visual Studio Community 2022 Version 17.5.3

Additional context
Boost & gcc-10 no problem.

I think this implementation is terrible:

// msvc 17.5.3
    _EXPORT_STD template <class _Rep, class _Period>
    void sleep_for(const chrono::duration<_Rep, _Period>& _Rel_time) {
        sleep_until(_To_absolute_time(_Rel_time));
    }
@MattStephanson
Copy link
Contributor

Looks like a duplicate of #718.

@UMU618
Copy link
Author

UMU618 commented Mar 31, 2023

Closed due to duplicate of #718.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants