#include <xtd/collections/generic/list>
#include <xtd/threading/manual_reset_event>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/startup>
 
 
namespace manual_reset_event_example {
  class program {
  public:
    static void main() {
      console::write_line("\nStart 3 named threads that block on a ManualresetEvent:\n");
      
      for(auto i = 0; i <= 2; ++i) {
        threads.emplace_back(thread_proc);
        threads.back().name(string::format("Thread_{}", i));
        threads.back().start();
      }
      
      thread::sleep(500);
      console::write_line("\nWhen all three threads have started, press Enter to call set()"
                          "\nto release all the threads.\n");
      console::read_line();
      
      mre.set();
      
      thread::sleep(500);
      console::write_line("\nWhen a ManualresetEvent is signaled, threads that call WaitOne()"
                          "\ndo not block. Press Enter to show this.\n");
      console::read_line();
      
      for(auto i = 3; i <= 4; ++i) {
        threads.emplace_back(thread_proc);
        threads.back().name(string::format("Thread_{}", i));
        threads.back().start();
      }
      
      thread::sleep(500);
      console::write_line("\nPress Enter to call reset(), so that threads once again block"
                          "\nwhen they call WaitOne().\n");
      console::read_line();
      
      mre.reset();
      
      
      threads.emplace_back(thread_proc);
      threads.back().name("Thread_5");
      threads.back().start();
 
      thread::sleep(500);
      console::write_line("\nPress Enter to call set() and conclude the demo.");
      console::read_line();
      
      mre.set();
    }
    
  private:
 
    
    
    
    static void thread_proc() {
      string name = thread::current_thread().name();
      
      console::write_line(name + " starts and calls mre.WaitOne()");
      
      mre.wait_one();
      
      console::write_line(name + " ends.");
    }
  };
}
 
startup_(manual_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, must be reset manually....
Definition manual_reset_event.hpp:35
 
#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