#include <xtd/collections/generic/list>
#include <xtd/threading/auto_reset_event>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/startup>
 
 
namespace auto_reset_event_example {
  class program {
  public:
    
    static auto main() {
      console::write_line("Press Enter to create three threads and start them.\r\n"
                          "The threads wait on auto_reset_event #1, which was created\r\n"
                          "in the signaled state, so the first thread is released.\r\n"
                          "This puts auto_reset_event #1 into the unsignaled state.");
      console::read_line();
      
      for (auto index = 1; index < 4; ++index) {
        threads.emplace_back(thread_proc);
        threads.back().name(string::format("Thread_{}", index));
        threads.back().start();
      }
      thread::sleep(250_ms);
      
      for (auto index = 0; index < 2; ++index) {
        console::write_line("Press Enter to release another thread.");
        console::read_line();
        event_1.set();
        thread::sleep(250_ms);
      }
      
      console::write_line("\r\nAll threads are now waiting on auto_reset_event #2.");
      for (int i = 0; i < 3; i++) {
        console::write_line("Press Enter to release a thread.");
        console::read_line();
        event_2.set();
        thread::sleep(250_ms);
      }
    }
    
    static void thread_proc() {
      string name = thread::current_thread().name();
      
      console::write_line("{0} waits on auto_reset_event #1.", name);
      event_1.wait_one();
      console::write_line("{0} is released from auto_reset_event #1.", name);
      
      console::write_line("{0} waits on auto_reset_event #2.", name);
      event_2.wait_one();
      console::write_line("{0} is released from auto_reset_event #2.", name);
      
      console::write_line("{0} ends.", name);
    }
 
  private:
  };
}
 
startup_(auto_reset_event_example::program::main);
 
 
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
 
Represents a thread synchronization event that, when signaled, resets automatically after releasing a...
Definition auto_reset_event.hpp:36
 
#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:175
 
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:15
 
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:11
 
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10