Contains a constant used to specify an infinite amount of time. This class cannot be inherited.
- Inheritance
- xtd::static_object → xtd::threading::timeout
- Header
#include <xtd/threading/timeout>
- Namespace
- xtd::threading
- Library
- xtd.core
- Example
- The following example shows a thread going to sleep for an infinite time and subsequently being woken up. As the xtd::threading::thread::interrupt method only works on the Windows operating system, on other platforms the result may be different.
#include <xtd/threading/interlocked>
#include <xtd/threading/thread>
#include <xtd/threading/thread_interrupted_exception>
#include <xtd/console>
#include <xtd/startup>
namespace timeout_example {
class stay_awake {
public:
stay_awake() = default;
void sleep_switch(bool value) {
sleep_switch_ = value;
}
void thread_method() {
while(!sleep_switch_) {
}
try {
"interrupted by main thread.");
}
}
private:
bool sleep_switch_ = false;
};
class thread_interrupt {
public:
static void main() {
auto stay_awake = timeout_example::stay_awake {};
auto new_thread = thread {
thread_start {stay_awake, &timeout_example::stay_awake::thread_method}};
new_thread.start();
new_thread.interrupt();
stay_awake.sleep_switch(true);
new_thread.join();
}
};
}
startup_(timeout_example::thread_interrupt::main);
|
static constexpr int32 | infinite = -1 |
| A constant used to specify an infinite waiting period. This field is constant. More...
|
|
static const time_span | infinite_time_span |
| A constant used to specify an infinite waiting period, for methods that accept a TimeSpan parameter. More...
|
|
◆ infinite
constexpr int32 xtd::threading::timeout::infinite = -1 |
|
static |
A constant used to specify an infinite waiting period. This field is constant.
- Examples:
- timeout.cpp.
◆ infinite_time_span
const time_span xtd::threading::timeout::infinite_time_span |
|
static |
A constant used to specify an infinite waiting period, for methods that accept a TimeSpan parameter.
The documentation for this class was generated from the following file: