tmp/tmpeqiq0w_9/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
## Semaphore <a id="thread.sema">[[thread.sema]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
Semaphores are lightweight synchronization primitives used to constrain
|
| 4 |
concurrent access to a shared resource. They are widely used to
|
| 5 |
implement other synchronization primitives and, whenever both are
|
| 6 |
applicable, can be more efficient than condition variables.
|
| 7 |
|
|
@@ -12,10 +14,11 @@ implementation of a counting semaphore with a unit resource count.
|
|
| 12 |
|
| 13 |
### Header `<semaphore>` synopsis <a id="semaphore.syn">[[semaphore.syn]]</a>
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
namespace std {
|
|
|
|
| 17 |
template<ptrdiff_t least_max_value = implementation-defined>
|
| 18 |
class counting_semaphore;
|
| 19 |
|
| 20 |
using binary_semaphore = counting_semaphore<1>;
|
| 21 |
}
|
|
@@ -23,11 +26,11 @@ namespace std {
|
|
| 23 |
|
| 24 |
### Class template `counting_semaphore` <a id="thread.sema.cnt">[[thread.sema.cnt]]</a>
|
| 25 |
|
| 26 |
``` cpp
|
| 27 |
namespace std {
|
| 28 |
-
template<ptrdiff_t least_max_value = implementation-defined>
|
| 29 |
class counting_semaphore {
|
| 30 |
public:
|
| 31 |
static constexpr ptrdiff_t max() noexcept;
|
| 32 |
|
| 33 |
constexpr explicit counting_semaphore(ptrdiff_t desired);
|
|
@@ -122,11 +125,11 @@ return `false` in the absence of contending semaphore operations.
|
|
| 122 |
void acquire();
|
| 123 |
```
|
| 124 |
|
| 125 |
*Effects:* Repeatedly performs the following steps, in order:
|
| 126 |
|
| 127 |
-
- Evaluates `try_acquire`. If the result is `true`, returns.
|
| 128 |
- Blocks on `*this` until `counter` is greater than zero.
|
| 129 |
|
| 130 |
*Throws:* `system_error` when an exception is
|
| 131 |
required [[thread.req.exception]].
|
| 132 |
|
|
|
|
| 1 |
## Semaphore <a id="thread.sema">[[thread.sema]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="thread.sema.general">[[thread.sema.general]]</a>
|
| 4 |
+
|
| 5 |
Semaphores are lightweight synchronization primitives used to constrain
|
| 6 |
concurrent access to a shared resource. They are widely used to
|
| 7 |
implement other synchronization primitives and, whenever both are
|
| 8 |
applicable, can be more efficient than condition variables.
|
| 9 |
|
|
|
|
| 14 |
|
| 15 |
### Header `<semaphore>` synopsis <a id="semaphore.syn">[[semaphore.syn]]</a>
|
| 16 |
|
| 17 |
``` cpp
|
| 18 |
namespace std {
|
| 19 |
+
// [thread.sema.cnt], class template counting_semaphore
|
| 20 |
template<ptrdiff_t least_max_value = implementation-defined>
|
| 21 |
class counting_semaphore;
|
| 22 |
|
| 23 |
using binary_semaphore = counting_semaphore<1>;
|
| 24 |
}
|
|
|
|
| 26 |
|
| 27 |
### Class template `counting_semaphore` <a id="thread.sema.cnt">[[thread.sema.cnt]]</a>
|
| 28 |
|
| 29 |
``` cpp
|
| 30 |
namespace std {
|
| 31 |
+
template<ptrdiff_t least_max_value = implementation-defined // default value for least_max_value template parameter of counting_semaphore>
|
| 32 |
class counting_semaphore {
|
| 33 |
public:
|
| 34 |
static constexpr ptrdiff_t max() noexcept;
|
| 35 |
|
| 36 |
constexpr explicit counting_semaphore(ptrdiff_t desired);
|
|
|
|
| 125 |
void acquire();
|
| 126 |
```
|
| 127 |
|
| 128 |
*Effects:* Repeatedly performs the following steps, in order:
|
| 129 |
|
| 130 |
+
- Evaluates `try_acquire()`. If the result is `true`, returns.
|
| 131 |
- Blocks on `*this` until `counter` is greater than zero.
|
| 132 |
|
| 133 |
*Throws:* `system_error` when an exception is
|
| 134 |
required [[thread.req.exception]].
|
| 135 |
|