BDE 4.14.0 Production release
|
Provide a semaphore class optimizing post
.
post
This component defines a semaphore, bslmt::FastPostSemaphore
, with the post
operation being optimized at the potential expense of other operations. In particular, bslmt::FastPostSemaphore
is an efficient synchronization primitive that enables sharing of a counted number of resources. bslmt::FastPostSemaphore
supports the methods timedWait
, enable
, and disable
in addition to the standard semaphore methods.
Commonly, during periods of time when the protected resource is scarce (the semaphore count is frequently zero) and threads are frequently blocked on wait methods, pessimizing the performance of the threads that block will have little effect on overall performance. In this case, optimizing post
may be a performance improvement. Note that when the resource is plentiful, there are no blocked threads and we expect the differences between semaphore implementations to be trivial.
bsls::SystemClockType
supplies the enumeration indicating the system clock on which timeouts supplied to other methods should be based. If the clock type indicated at construction is bsls::SystemClockType::e_REALTIME
, the absTime
argument passed to the timedWait
method should be expressed as an absolute offset since 00:00:00 UTC, January 1, 1970 (which matches the epoch used in bsls::SystemTime::now(bsls::SystemClockType::e_REALTIME)
. If the clock type indicated at construction is bsls::SystemClockType::e_MONOTONIC
, the absTime
argument passed to the timedWait
method should be expressed as an absolute offset since the epoch of this clock (which matches the epoch used in bsls::SystemTime::now(bsls::SystemClockType::e_MONOTONIC)
.
This section illustrates intended use of this component.
This example illustrates a very simple fixed-size queue where potential clients can push integers to a queue, and later retrieve the integer values from the queue in FIFO order. Also, waitUntilEmpty
is implemented to depict the common usage of getDisabledState
.
First, we define the IntQueue
class:
Next, implement the queue:
Then, declare an instance of IntQueue
:
Next, populate some values:
Now, pop and verify the values:
Finally, use waitUntilEmpty
to verify the queue is empty: