Limits the number of threads that can access a resource or pool of resources concurrently.
Public Constructors | |
semaphore () | |
Initializes a new instance of the xtd::threading::semaphore class. | |
semaphore (const string &name) | |
nitializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying the name of a system semaphore object. | |
semaphore (const string &name, bool &created_new) | |
nitializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created. | |
semaphore (int32 initial_count) | |
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries. | |
semaphore (int32 initial_count, const string &name) | |
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, optionally specifying the name of a system semaphore object. | |
semaphore (int32 initial_count, const string &name, bool &created_new) | |
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, optionally specifying the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created. | |
semaphore (int32 initial_count, int32 maximum_count) | |
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries. | |
semaphore (int32 initial_count, int32 maximum_count, const string &name) | |
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, and optionally specifying the name of a system semaphore object. | |
semaphore (int32 initial_count, int32 maximum_count, const string &name, bool &created_new) | |
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, optionally specifying the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created. | |
Public Properties | |
intptr | handle () const noexcept override |
Gets the native operating system handle. | |
void | handle (intptr value) override |
Sets the native operating system handle. | |
Public Methods | |
void | close () override |
Releases all resources held by the current xtd::threading::wait_handle. | |
int32 | compare_to (const semaphore &value) const noexcept override |
bool | equals (const semaphore &value) const noexcept override |
int32 | release () |
Exits the semaphore and returns the previous count. | |
int32 | release (int32 release_count) |
Exits the semaphore a specified number of times and returns the previous count. | |
virtual bool | equals (const object &obj) const noexcept |
Determines whether the specified object is equal to the current 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. | |
Public Static Methods | |
static semaphore | open_existing (const string &name) |
Opens the specified named semaphore, if it already exists. | |
static bool | try_open_existing (const string &name, semaphore &result) noexcept |
Opens the specified named semaphore, if it already exists, and returns a value that indicates whether the operation succeeded. | |
Protected Methods | |
bool | signal () override |
Releases ownership of the specified wait_handle object. | |
bool | wait (int32 milliseconds_timeout) override |
wait ownership of the specified mutex object. | |
Additional Inherited Members | |
Static Public Attributes inherited from xtd::threading::wait_handle | |
static const intptr | invalid_handle |
Represents an invalid native operating system handle. This field is read-only. | |
static constexpr size_t | wait_timeout |
Indicates that a xtd::threading::wait_handle::wait_any operation timed out before any of the wait handles were signaled. This field is constant. | |
Public Member Functions inherited from xtd::threading::wait_handle | |
wait_handle ()=default | |
Initializes a new instance of the xtd::threading::wait_handle class. | |
virtual bool | wait_one () |
Blocks the current thread until the current xtd::threading::wait_handle receives a signal. | |
virtual bool | wait_one (int32 milliseconds_timeout) |
Blocks the current thread until the current xtd::threading::wait_handle receives a signal, using 32-bit signed integer to measure the time interval. | |
virtual bool | wait_one (const time_span &timeout) |
Blocks the current thread until the current instance receives a signal, using a xtd::time_span to measure the time interval. | |
Public Member Functions inherited from xtd::object | |
object ()=default | |
Create a new instance of the ultimate base class 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. | |
Public Member Functions inherited from xtd::icomparable< semaphore > | |
virtual int32 | compare_to (const semaphore &obj) const noexcept=0 |
Compares the current instance with another object of the same type. | |
Public Member Functions inherited from xtd::iequatable< semaphore > | |
virtual bool | equals (const semaphore &) const noexcept=0 |
Indicates whether the current object is equal to another object of the same type. | |
Static Public Member Functions inherited from xtd::threading::wait_handle | |
static bool | signal_and_wait (wait_handle &to_signal, wait_handle &to_wait) |
Signals one xtd::threading::wait_handle and waits on another. | |
static bool | signal_and_wait (wait_handle &to_signal, wait_handle &to_wait, int32 milliseconds_timeout) |
Signals one xtd::threading::wait_handle and waits on another, specifying a time-out interval as a 32-bit signed integer. | |
static bool | signal_and_wait (wait_handle &to_signal, wait_handle &to_wait, const time_span &timeout) |
Signals one xtd::threading::wait_handle and waits on another, specifying a time-out interval as a time_span. | |
template<typename collection_t > | |
static bool | wait_all (const collection_t &wait_handles) |
Waits for all the elements in the specified collection to receive a signal. | |
template<typename collection_t > | |
static bool | wait_all (const collection_t &wait_handles, int32 milliseconds_timeout) |
Waits for all the elements in the specified collection to receive a signal, using an int32 value to measure the time interval. | |
template<typename collection_t > | |
static bool | wait_all (const collection_t &wait_handles, const time_span &timeout) |
Waits for all the elements in the specified collection to receive a signal, using a xtd::time_span value to measure the time interval. | |
template<typename collection_t > | |
static size_t | wait_any (const collection_t &wait_handles) |
Waits for any of the elements in the specified collection to receive a signal. | |
template<typename collection_t > | |
static size_t | wait_any (const collection_t &wait_handles, int32 milliseconds_timeout) |
Waits for any of the elements in the specified collection to receive a signal, using a 32-bit signed integer to measure the time interval. | |
template<typename collection_t > | |
static size_t | wait_any (const collection_t &wait_handles, const time_span &timeout) |
Waits for any of the elements in the specified collection to receive a signal, using a xtd::time_span to measure the time interval. | |
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. | |
Protected Member Functions inherited from xtd::threading::wait_handle | |
Protected Member Functions inherited from xtd::abstract_object | |
abstract_object ()=default | |
Initializes a new instance of the xtd::abstract_object class. | |
xtd::threading::semaphore::semaphore | ( | ) |
Initializes a new instance of the xtd::threading::semaphore class.
|
explicit |
nitializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying the name of a system semaphore object.
name | The name, if the synchronization object is to be shared with other processes; otherwise, null or an empty string. The name is case-sensitive. The backslash character () is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name. |
xtd::io::io_exception | name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local" are case-sensitive. -or- There was some other error. The HResult property may provide more information. |
|
explicit |
nitializes a new instance of the xtd::threading::semaphore class, specifying optionally specifying the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created.
name | The name, if the synchronization object is to be shared with other processes; otherwise, null or an empty string. The name is case-sensitive. The backslash character () is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name. |
created_new | When this method returns, contains true if a local semaphore was created (that is, if name is null or an empty string) or if the specified named system semaphore was created; false if the specified named system semaphore already existed. This parameter is passed uninitialized. |
xtd::io::io_exception | name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local" are case-sensitive. -or- There was some other error. The HResult property may provide more information. |
|
explicit |
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries.
initial_count | The initial number of requests for the semaphore that can be granted concurrently. |
xtd::argument_out_of_range_exception | initial_count is less than 0. |
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, optionally specifying the name of a system semaphore object.
initial_count | The initial number of requests for the semaphore that can be granted concurrently. |
name | The name, if the synchronization object is to be shared with other processes; otherwise, null or an empty string. The name is case-sensitive. The backslash character () is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name. |
xtd::argument_out_of_range_exception | initial_count is less than 0. |
xtd::io::io_exception | name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local" are case-sensitive. -or- There was some other error. The HResult property may provide more information. |
xtd::threading::semaphore::semaphore | ( | int32 | initial_count, |
const string & | name, | ||
bool & | created_new | ||
) |
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, optionally specifying the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created.
initial_count | The initial number of requests for the semaphore that can be granted concurrently. |
name | The name, if the synchronization object is to be shared with other processes; otherwise, null or an empty string. The name is case-sensitive. The backslash character () is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name. |
created_new | When this method returns, contains true if a local semaphore was created (that is, if name is null or an empty string) or if the specified named system semaphore was created; false if the specified named system semaphore already existed. This parameter is passed uninitialized. |
xtd::argument_out_of_range_exception | initial_count is less than 0. |
xtd::io::io_exception | name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local" are case-sensitive. -or- There was some other error. The HResult property may provide more information. |
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries.
initial_count | The initial number of requests for the semaphore that can be granted concurrently. |
maximum_count | The maximum number of requests for the semaphore that can be granted concurrently. |
xtd::argument_exception | initial_count is greater than maximum_count. |
xtd::argument_out_of_range_exception | maximum_count is less than 1. -or- initial_count is less than 0. |
xtd::threading::semaphore::semaphore | ( | int32 | initial_count, |
int32 | maximum_count, | ||
const string & | name | ||
) |
Initializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, and optionally specifying the name of a system semaphore object.
initial_count | The initial number of requests for the semaphore that can be granted concurrently. |
maximum_count | The maximum number of requests for the semaphore that can be granted concurrently. |
name | The name, if the synchronization object is to be shared with other processes; otherwise, null or an empty string. The name is case-sensitive. The backslash character () is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name. |
xtd::argument_exception | initial_count is greater than maximum_count. |
xtd::argument_out_of_range_exception | maximum_count is less than 1. -or- initial_count is less than 0. |
xtd::io::io_exception | name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local" are case-sensitive. -or- There was some other error. The HResult property may provide more information. |
xtd::threading::semaphore::semaphore | ( | int32 | initial_count, |
int32 | maximum_count, | ||
const string & | name, | ||
bool & | created_new | ||
) |
nitializes a new instance of the xtd::threading::semaphore class, specifying the initial number of entries and the maximum number of concurrent entries, optionally specifying the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created.
initial_count | The initial number of requests for the semaphore that can be granted concurrently. |
maximum_count | The maximum number of requests for the semaphore that can be granted concurrently. |
name | The name, if the synchronization object is to be shared with other processes; otherwise, null or an empty string. The name is case-sensitive. The backslash character () is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name. |
created_new | When this method returns, contains true if a local semaphore was created (that is, if name is null or an empty string) or if the specified named system semaphore was created; false if the specified named system semaphore already existed. This parameter is passed uninitialized. |
xtd::argument_exception | initial_count is greater than maximum_count. |
xtd::argument_out_of_range_exception | maximum_count is less than 1. -or- initial_count is less than 0. |
xtd::io::io_exception | name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. Note that the name and common prefixes "Global\" and "Local" are case-sensitive. -or- There was some other error. The HResult property may provide more information. |
|
overridevirtualnoexcept |
Gets the native operating system handle.
Implements xtd::threading::wait_handle.
|
overridevirtual |
Sets the native operating system handle.
value | An intptr representing the native operating system handle. |
Implements xtd::threading::wait_handle.
|
overridevirtual |
Releases all resources held by the current xtd::threading::wait_handle.
Reimplemented from xtd::threading::wait_handle.
int32 xtd::threading::semaphore::release | ( | ) |
Exits the semaphore and returns the previous count.
xtd::threading::semaphore_full_exception | The semaphore count is already at the maximum value. |
xtd::io::io_exception | A Win32 or pthred error occurred with a named semaphore. |
Exits the semaphore a specified number of times and returns the previous count.
release_count | The number of times to exit the semaphore. |
xtd::argument_out_of_range_exception | releaseCount is less than 1. |
xtd::threading::semaphore_full_exception | The semaphore count is already at the maximum value. |
Opens the specified named semaphore, if it already exists.
name | The name of the synchronization object to be shared with other processes. The name is case-sensitive. |
xtd::argument_exception | name is an empty string. |
xtd::io::io_exception | name is invalid. This can be for various reasons, including some restrictions that may be placed by the operating system, such as an unknown prefix or invalid characters. -or- There was some other error. The HResult property may provide more information. |
|
staticnoexcept |
Opens the specified named semaphore, if it already exists, and returns a value that indicates whether the operation succeeded.
name | The name of the synchronization object to be shared with other processes. The name is case-sensitive. The backslash character () is reserved and may only be used to specify a namespace. For more information on namespaces, see the remarks section. There may be further restrictions on the name depending on the operating system. For example, on Unix-based operating systems, the name after excluding the namespace must be a valid file name. |
result | When this method returns, contains a xtd::threading::semaphore object that represents the named semaphore if the call succeeded. |
|
overrideprotectedvirtual |
Releases ownership of the specified wait_handle object.
Implements xtd::threading::wait_handle.
|
overrideprotectedvirtual |
wait ownership of the specified mutex object.
handle | A valid handle to an open object. |
milliseconds_timeout | The number of milliseconds to wait, or -1 to wait indefinitely. |
Implements xtd::threading::wait_handle.
|
virtualnoexcept |
Determines whether the specified object is equal to the current object.
obj | The object to compare with the current object. |
Reimplemented from xtd::object.
|
inlinestaticnoexcept |
Determines whether the specified object instances are considered equal.
object_a | The first object to compare. |
object_b | The second object to compare. |