xtd 0.2.0
Loading...
Searching...
No Matches
thread_pool.cpp

Shows how to use xtd::threading::thread_pool class.

#include <xtd/threading/auto_reset_event>
#include <xtd/threading/thread_pool>
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/random>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::threading;
namespace wait_handle_example {
class program {
public:
static void main() {
// Queue the task.
thread_pool::queue_user_work_item({thread_proc});
console::write_line("Main thread does some work, then sleeps.");
thread::sleep(1000);
console::write_line("Main thread exits.");
}
private:
// This thread procedure performs the task.
static void thread_proc(std::any state_info) {
// No state object was passed to queue_user_work_item, so state_info has no value.
console::write_line("Hello from the thread pool.");
}
};
}
startup_(wait_handle_example::program::main);
// This example produces output similar to the following:
//
// Main thread does some work, then sleeps.
// Hello from the thread pool.
// Main thread exits.
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10