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:45
countdown_event(xtd::size initial_count)
Initializes a new instance of xtd::threading::countdown_event class with the specified count.
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/xtd>
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_pool::queue_user_work_item(thread_proc);
countdown_event.wait();
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
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Represents a synchronization primitive that is signaled when its count reaches zero.
Definition countdown_event.hpp:30
auto signal() -> bool
Registers a signal with the xtd::threading::countdown_event, decrementing the value of xtd::threading...
auto wait() -> void
Blocks the current thread until the xtd::threading::countdown_event is set.
static thread & current_thread() noexcept
Gets the currently running thread.
#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:282
@ i
The I key.
Definition console_key.hpp:104

Public Constructors

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

Public Properties

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

Public Methods

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

 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 xtd::size 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<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const
 Returns a xtd::string that represents the current object.
 
template<class object_a_t, class 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<class object_a_t, class 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 ( xtd::size 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()

auto xtd::threading::countdown_event::current_count ( ) const -> xtd::size
nodiscard

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()

auto xtd::threading::countdown_event::initial_count ( ) const -> xtd::size
nodiscard

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()

auto xtd::threading::countdown_event::is_set ( ) const -> bool
nodiscard

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]

auto xtd::threading::countdown_event::wait_handle ( ) const -> const xtd::threading::wait_handle &
nodiscard

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]

auto xtd::threading::countdown_event::wait_handle ( ) -> xtd::threading::wait_handle &
nodiscard

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]

auto xtd::threading::countdown_event::add_count ( ) -> void

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]

auto xtd::threading::countdown_event::add_count ( xtd::size count) -> void

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()

auto xtd::threading::countdown_event::close ( ) -> void

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

◆ reset() [1/2]

auto xtd::threading::countdown_event::reset ( ) -> void

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 ( xtd::size 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]

auto xtd::threading::countdown_event::signal ( ) -> bool

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.

◆ signal() [2/2]

auto xtd::threading::countdown_event::signal ( xtd::size signal_count) -> bool

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]

auto xtd::threading::countdown_event::try_add_count ( ) -> bool
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]

auto xtd::threading::countdown_event::try_add_count ( xtd::size count) -> bool
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]

auto xtd::threading::countdown_event::wait ( ) -> void

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.

◆ wait() [2/6]

auto xtd::threading::countdown_event::wait ( xtd::int32 milliseconds_timeout) -> bool

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]

auto xtd::threading::countdown_event::wait ( const cancellation_token & cancellation_token) -> void

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]

auto xtd::threading::countdown_event::wait ( const xtd::time_span & timeout) -> bool

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]

auto xtd::threading::countdown_event::wait ( xtd::int32 milliseconds_timeout,
const cancellation_token & cancellation_token ) -> bool

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]

auto xtd::threading::countdown_event::wait ( const xtd::time_span & timeout,
const cancellation_token & cancellation_token ) -> bool

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: