#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.interrupt();
stay_awake.sleep_switch(true);
new_thread.join();
}
};
}
startup_(timeout_example::thread_interrupt::main);
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The exception that is thrown when a Thread is interrupted while it is in a waiting state.
Definition thread_interrupted_exception.hpp:24
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.hpp:45
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
void start()
Causes the operating system to change the state of the current instance to xtd::threading::thread_sta...
static void spin_wait(int32 iterations)
Causes a thread to wait the number of times defined by the iterations parameter.
static constexpr int32 infinite
A constant used to specify an infinite waiting period. This field is constant.
Definition timeout.hpp:41
xtd::delegate< void()> thread_start
Represents the method that executes on a xtd::threading::thread.
Definition thread_start.hpp:24
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168
@ e
The E key.
Definition console_key.hpp:96
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8