Tags down


Possible problem of gcc with sleep_for and sleep_until functions

By : Saied Ayad
Date : September 17 2020, 08:00 AM
With these it helps This is indeed a stunning bug, fixed in GCC 10 (bug 41861 describes it in the context of ).
Back in the day when I encountered this, it was tempting to fall back on Boost to get the proper behaviour, but even that was broken until 1.61. And nowadays it would be strange to mix Boost and standard timing/threading code anyway, since the standard facilities are generally mature and preferred (irony detected!).
code :

Share : facebook icon twitter icon

Inputs to sleep_until()

By : Bran Dao
Date : March 29 2020, 07:55 AM
I wish did fix the issue. To wait until a specified clock time, you need to get a time_t that represents that clock time, and then use std::chrono::system_clock::from_time_t to create a std::chrono::system_clock::time_point which you can then use with the xxx_until functions such as std::this_thread::sleep_until.
code :
void foo(){
    tm timeout_tm={0};
    // set timeout_tm to 14:00:01 today
    timeout_tm.tm_year = 2013 - 1900;
    timeout_tm.tm_mon = 7 - 1;
    timeout_tm.tm_mday = 10;
    timeout_tm.tm_hour = 14;
    timeout_tm.tm_min = 0;
    timeout_tm.tm_sec = 1;
    timeout_tm.tm_isdst = -1;
    time_t timeout_time_t=mktime(&timeout_tm);
    std::chrono::system_clock::time_point timeout_tp=

C++11 std::this_thread - How to cancel sleep_until ()?

By : Wenfeng Hong
Date : March 29 2020, 07:55 AM
hope this fix your issue I don't think you can do this with sleep_until. Have a look at condition variables ( http://www.cplusplus.com/reference/condition_variable/condition_variable/ ). Should be usable for exactly what you want.

What is the maximum value I can pass to std::thread::sleep_for() and sleep_until()?

By : Sethulakshmi P
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It's unspecified, and it will overflow
I've had discussions with Billy O'Neal, one of the Visual C++ standard library developers, and Howard Hinnant, lead author of libc++. My conclusion is that the _for and _until family from the threading library will overflow in unspecified ways and you should not try to pass largish values to them. Whether the standard is under-specified on that subject is unclear to me.
code :
auto s = duration_cast<seconds>(time);
auto ns = duration_cast<nanoseconds>(time - s);

timespec ts = { s.count(), ns.count() };
nanosleep(&ts, &ts);

C++11 std::this_thread::sleep_until() hangs when compiled with GCC 4.8.5

By : Saurabh kr. Gupta
Date : March 29 2020, 07:55 AM
I hope this helps . This is a confirmed bug that was fixed in gcc 4.9.

sleep_until a timepoint in the past

By : user1601840
Date : March 29 2020, 07:55 AM
This might help you Looks like a bug:
30.2.4 Timing specifications [thread.req.timing]
Related Posts Related Posts :
  • Can't std::cout a max_element function
  • How to solve error (projectname has triggered breakpoint)?
  • Dynamic 2D array without using new
  • I need help creating a scoring system, but it keeps giving me an error, the commented out integers are the parts giving
  • Pushing a string to a private member vector
  • Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace
  • Is it possible to add two indexes of a string to a character to then convert that character to an int in c++?
  • How to copy few variables to other variable?
  • Short Parameter Type in C++
  • Build a compile time command look up table using template metaprogramming
  • Explicitly calling a destructor when you only have a shared_ptr to the base class?
  • How do compilers know C++ constexpr computations do not trigger undefined behavior?
  • Adding a Node in a Singly linked lists (supports adding in front, end and middle)
  • What should I use to read integers from a file
  • Is any use of a union clearly well defined, in any revision of C++?
  • Is it possible to create iterators with C++14 that are C++17 compliant?
  • Is it crucial to know by which compiler a specific binary generated in C++?
  • Mixing separately compiled objects
  • Sort unique values from a map<string, vector<string>>
  • How does shared_ptr work in c++ without initialization
  • visual C++ professional
  • What is the best way to pass uint8_t* buffer and size_t bufferlen to API function in C from a C++
  • Writing a function for arranging the elements in an array
  • C++ Linked List Node Refers to Itself
  • Limit variable template to a list of types
  • How can I use the function std::min() to calculate the minimum?
  • How to return a value from a constant array in a single line in C++
  • How to use QtCreator instead of gdb to debug C++ code in an R package based on Rcpp
  • How to elide copy when chaining?
  • Why c++ use throw() keyword to indicate the function won't throw any exceptions
  • specifying arguments to the compare function in C++ sort
  • How to ignore specific bits in a 32-bit integer
  • Prevent gcc from mangling my AVX2 intrinsics copy into REP MOVS
  • Is it possible to make a function return a typename in C++?
  • getline method only working once in nested loop
  • Is it ok to return default argument's value by const reference?
  • function with variable number of arguments that are converted to a string
  • if (static_cast<bool>(x)) vs if (x)
  • Mapping from a size to the corresponding uintN_t type
  • C++ to Assembly
  • How to check answers through an answer set using c++?
  • What does the address of a vector represent?
  • Polymorphic member class for non-virtual base
  • Arduino shows odd behaviour with LED output in loop
  • C++20 std::atomic<float>- std::atomic<double>.specializations
  • reading variable length input in C++ using stream
  • Why does a memory leak occur in this code when a bad_alloc exception is thrown for T2
  • Passing an object as a parameter in C++
  • why we using arrow and dot opertor only for user defined data types why not for primitive data types?
  • identifier "in" is undefined
  • Is there a tool to identify what external identifiers a set of C++ source files refer to?
  • Overloading << for both iostream and fstream
  • Zero cost abstraction for executing same statement on multiple objects
  • Const reference to temporary object does not extend its lifetime
  • Extracting decimal points in C++
  • Unable to get output for multiplication
  • no matching operator delete found; memory will not be freed if initialization throws an exception
  • Connect a UDP socket, but still receive datagrams from other sources
  • How to access elements of vector of pairs using a pointer?
  • Class is not a template error when converting code from non-template to templates
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk