xtd 0.2.0
Loading...
Searching...
No Matches
xtd::threading::countdown_event Class Reference
Inheritance diagram for xtd::threading::countdown_event:
xtd::object

Definition

Represents a synchronization primitive that is signaled when its count reaches zero.

Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
Represents a synchronization primitive that is signaled when its count reaches zero.
Definition countdown_event.hpp:30
Header
#include <xtd/threading/countdown_event>
Namespace
xtd::threading
Library
xtd.core
Examples
The following example shows how to use a xtd::threading::countdown_event:
#include <xtd/threading/countdown_event>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::threading;
namespace monitor_lock_example {
class program {
public:
static void main() {
auto thread_proc = [&] {
console::write_line("Thread {} signals countdown_event", thread::current_thread().managed_thread_id());
};
for (auto i = 0; i < 5; ++i)
thread::start_new(thread_proc);
console::write_line("All threads have signaled countdown_event");
}
};
}
startup_(monitor_lock_example::program::main);
// This example produces output similar to the following:
//
// Thread 2 signals countdown_event
// Thread 3 signals countdown_event
// Thread 4 signals countdown_event
// Thread 6 signals countdown_event
// Thread 5 signals countdown_event
// All threads have signaled countdown_event
void wait()
Blocks the current thread until the xtd::threading::countdown_event is set.
bool signal()
Registers a signal with the xtd::threading::countdown_event, decrementing the value of xtd::threading...
#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
@ i
The I key.
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
Examples
countdown_event.cpp.

Public Constructors

 countdown_event (int32 initial_count)
 Initializes a new instance of xtd::threading::countdown_event class with the specified count.
 

Public Properties

int32 current_count () const
 Gets the number of remaining signals required to set the event.
 
int32 initial_count () const
 Gets the numbers of signals initially required to set the event.
 
bool is_set () const
 ndicates whether the xtd::threading::countdown_event object's current count has reached zero.
 
const xtd::threading::wait_handlewait_handle () const
 Gets a xtd::threading::wait_handle that is used to wait for the event to be set.
 
xtd::threading::wait_handlewait_handle ()
 Gets a xtd::threading::wait_handle that is used to wait for the event to be set.
 

Public Methods

void add_count ()
 Increments the xtd::threading::countdown_event's current count by one.
 
void add_count (int32 count)
 Increments the xtd::threading::countdown_event's current count by one.
 
void close ()
 Close the current instance of the xtd::threading::countdown_event class.
 
void reset ()
 Resets the xtd::threading::countdown_event to the value of xtd::threading::countdown_event::initial_count.
 
void reset (int32 count)
 Resets the xtd::threading::countdown_event::initial_count property to a specified value.
 
bool signal ()
 Registers a signal with the xtd::threading::countdown_event, decrementing the value of xtd::threading::countdown_event::current_count.
 
bool signal (int32 signal_count)
 Registers multiple signals with the xtd::threading::countdown_event, decrementing the value of xtd::threading::countdown_event::current_count by the specified amount.
 
bool try_add_count () noexcept
 Attempts to increment xtd::threading::countdown_event::current_count by one.
 
bool try_add_count (int32 count) noexcept
 Attempts to increment xtd::threading::countdown_event::current_count by by a specified value.
 
void wait ()
 Blocks the current thread until the xtd::threading::countdown_event is set.
 
bool wait (int32 milliseconds_timeout)
 Blocks the current thread until the xtd::threading::countdown_event is set, using a 32-bit signed integer to measure the timeout.
 
void wait (const cancellation_token &cancellation_token)
 Blocks the current thread until the xtd::threading::countdown_event is set, while observing a xtd::threading::cancellation_token.
 
bool wait (const time_span &timeout)
 Blocks the current thread until the xtd::threading::countdown_event is set, using a xtd::time_span to measure the timeout.
 
bool wait (int32 milliseconds_timeout, const cancellation_token &cancellation_token)
 Blocks the current thread until the xtd::threading::countdown_event is set, using a 32-bit signed integer to measure the timeout, while observing a xtd::threading::cancellation_token.
 
bool wait (const time_span &timeout, const cancellation_token &cancellation_token)
 Blocks the current thread until the xtd::threading::countdown_event is set, using a xtd::time_span to measure the timeout, while observing a xtd::threading::cancellation_token.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const noexcept
 Returns a xtd::string that represents the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ countdown_event()

xtd::threading::countdown_event::countdown_event ( int32  initial_count)
explicit

Initializes a new instance of xtd::threading::countdown_event class with the specified count.

Parameters
initial_counthe number of signals initially required to set the xtd::threading::countdown_event.
Exceptions
xtd::argument_out_of_range_exceptioninitial_count is less than 0.
Remarks
If initial_count is 0, the event is created in a signaled state.

Member Function Documentation

◆ current_count()

int32 xtd::threading::countdown_event::current_count ( ) const

Gets the number of remaining signals required to set the event.

Returns
The number of remaining signals required to set the event.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.

◆ initial_count()

int32 xtd::threading::countdown_event::initial_count ( ) const

Gets the numbers of signals initially required to set the event.

Returns
The number of signals initially required to set the event.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.

◆ is_set()

bool xtd::threading::countdown_event::is_set ( ) const

ndicates whether the xtd::threading::countdown_event object's current count has reached zero.

Returns
true if the current count is zero; otherwise, false.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
Remarks
The xtd::threading::countdown_event does not raise an event when the countdown has reached zero. Instead, the xtd::threading::countdown_event::current_count property equals zero, and the xtd::threading::countdown_event::is_set property equals true.

◆ wait_handle() [1/2]

const xtd::threading::wait_handle & xtd::threading::countdown_event::wait_handle ( ) const

Gets a xtd::threading::wait_handle that is used to wait for the event to be set.

Returns
A xtd::threading::wait_handle that is used to wait for the event to be set.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.

◆ wait_handle() [2/2]

xtd::threading::wait_handle & xtd::threading::countdown_event::wait_handle ( )

Gets a xtd::threading::wait_handle that is used to wait for the event to be set.

Returns
A xtd::threading::wait_handle that is used to wait for the event to be set.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.

◆ add_count() [1/2]

void xtd::threading::countdown_event::add_count ( )

Increments the xtd::threading::countdown_event's current count by one.

Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::invalid_operation_exceptionThe current instance is already set.

◆ add_count() [2/2]

void xtd::threading::countdown_event::add_count ( int32  count)

Increments the xtd::threading::countdown_event's current count by one.

Parameters
countThe value by which to increase xtd::threading::countdown_event::current_count.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::invalid_operation_exceptionThe current instance is already set.
xtd::argument_out_of_range_exceptioncount is less than 0.

◆ close()

void xtd::threading::countdown_event::close ( )

Close the current instance of the xtd::threading::countdown_event class.

◆ reset() [1/2]

void xtd::threading::countdown_event::reset ( )

Resets the xtd::threading::countdown_event to the value of xtd::threading::countdown_event::initial_count.

Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
Remarks
This method resets xtd::threading::countdown_event::initial_count for all subsequent accesses of the property on the current instance.

◆ reset() [2/2]

void xtd::threading::countdown_event::reset ( int32  count)

Resets the xtd::threading::countdown_event::initial_count property to a specified value.

Parameters
counthe number of signals required to set the xtd::threading::countdown_event.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::argument_out_of_range_exceptioncount is less than 0.
Remarks
This method resets xtd::threading::countdown_event::initial_count for all subsequent accesses of the property on the current instance.

◆ signal() [1/2]

bool xtd::threading::countdown_event::signal ( )

Registers a signal with the xtd::threading::countdown_event, decrementing the value of xtd::threading::countdown_event::current_count.

Returns
true if the signal caused the count to reach zero and the event was set; otherwise, false.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::nvalid_operation_exceptionThe current instance is already set.
Examples
countdown_event.cpp.

◆ signal() [2/2]

bool xtd::threading::countdown_event::signal ( int32  signal_count)

Registers multiple signals with the xtd::threading::countdown_event, decrementing the value of xtd::threading::countdown_event::current_count by the specified amount.

Parameters
signal_countThe number of signals to register.
Returns
true if the signal caused the count to reach zero and the event was set; otherwise, false.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::argument_out_of_range_exceptionsignal_count is less than 0.
xtd::nvalid_operation_exceptionThe current instance is already set.

◆ try_add_count() [1/2]

bool xtd::threading::countdown_event::try_add_count ( )
noexcept

Attempts to increment xtd::threading::countdown_event::current_count by one.

Returns
true if the increment succeeded; otherwise, false. If CurrentCount is already at zero, this method will return false.

◆ try_add_count() [2/2]

bool xtd::threading::countdown_event::try_add_count ( int32  count)
noexcept

Attempts to increment xtd::threading::countdown_event::current_count by by a specified value.

Parameters
countThe value by which to increase xtd::threading::countdown_event::current_count.
Returns
true if the increment succeeded; otherwise, false. If CurrentCount is already at zero, this method will return false.

◆ wait() [1/6]

void xtd::threading::countdown_event::wait ( )

Blocks the current thread until the xtd::threading::countdown_event is set.

Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
Remarks
The caller of this method blocks indefinitely until the current instance is set. The caller will return immediately if the event is currently in a set state.
Examples
countdown_event.cpp.

◆ wait() [2/6]

bool xtd::threading::countdown_event::wait ( int32  milliseconds_timeout)

Blocks the current thread until the xtd::threading::countdown_event is set, using a 32-bit signed integer to measure the timeout.

Parameters
milliseconds_timeoutThe number of milliseconds to wait, or xtd::threading::timeout::ifinite (-1) to wait indefinitely.
Returns
true if the xtd::threading::countdown_event was set; otherwise, false.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::argument_out_of_range_exceptionmilliseconds_timeout is a negative number other than -1, which represents an infinite time-out..

◆ wait() [3/6]

void xtd::threading::countdown_event::wait ( const cancellation_token cancellation_token)

Blocks the current thread until the xtd::threading::countdown_event is set, while observing a xtd::threading::cancellation_token.

Parameters
cancellation_tokerThe xtd::threading::cancellation_token to observe.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::operation_canceled_exceptioncancellation_token has been canceled.
Remarks
The caller of this method blocks indefinitely until the current instance is set. The caller will return immediately if the event is currently in a set state. If the xtd::threading::cancellation_token being observed is canceled during the wait operation, an xtd::operation_canceled_exception will be thrown.

◆ wait() [4/6]

bool xtd::threading::countdown_event::wait ( const time_span timeout)

Blocks the current thread until the xtd::threading::countdown_event is set, using a xtd::time_span to measure the timeout.

Parameters
timeoutA xtd::time_span that represents the number of milliseconds to wait, or a xtd::time_span that represents -1 milliseconds to wait indefinitely.
Returns
true if the xtd::threading::countdown_event was set; otherwise, false.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::argument_out_of_range_exceptionmilliseconds_timeout is a negative number other than -1, which represents an infinite time-out..

◆ wait() [5/6]

bool xtd::threading::countdown_event::wait ( int32  milliseconds_timeout,
const cancellation_token cancellation_token 
)

Blocks the current thread until the xtd::threading::countdown_event is set, using a 32-bit signed integer to measure the timeout, while observing a xtd::threading::cancellation_token.

Parameters
milliseconds_timeoutThe number of milliseconds to wait, or xtd::threading::timeout::ifinite (-1) to wait indefinitely.
cancellation_tokerThe xtd::threading::cancellation_token to observe.
Returns
true if the xtd::threading::countdown_event was set; otherwise, false.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::operation_canceled_exceptioncancellation_token has been canceled.
xtd::argument_out_of_range_exceptionmilliseconds_timeout is a negative number other than -1, which represents an infinite time-out..

◆ wait() [6/6]

bool xtd::threading::countdown_event::wait ( const time_span timeout,
const cancellation_token cancellation_token 
)

Blocks the current thread until the xtd::threading::countdown_event is set, using a xtd::time_span to measure the timeout, while observing a xtd::threading::cancellation_token.

Parameters
timeoutA xtd::time_span that represents the number of milliseconds to wait, or a xtd::time_span that represents -1 milliseconds to wait indefinitely.
cancellation_tokerThe xtd::threading::cancellation_token to observe.
Returns
true if the xtd::threading::countdown_event was set; otherwise, false.
Exceptions
xtd::object_closed_exceptionThe current instance has already been closed.
xtd::operation_canceled_exceptioncancellation_token has been canceled.
xtd::argument_out_of_range_exceptionmilliseconds_timeout is a negative number other than -1, which represents an infinite time-out..

The documentation for this class was generated from the following file: