tmp/tmpm1dqmk2i/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Shared mutex types <a id="thread.sharedmutex.requirements">[[thread.sharedmutex.requirements]]</a>
|
| 2 |
+
|
| 3 |
+
The standard library types `shared_mutex` and `shared_timed_mutex` are
|
| 4 |
+
*shared mutex types*. Shared mutex types shall meet the requirements of
|
| 5 |
+
mutex types ([[thread.mutex.requirements.mutex]]), and additionally
|
| 6 |
+
shall meet the requirements set out below. In this description, `m`
|
| 7 |
+
denotes an object of a shared mutex type.
|
| 8 |
+
|
| 9 |
+
In addition to the exclusive lock ownership mode specified in
|
| 10 |
+
[[thread.mutex.requirements.mutex]], shared mutex types provide a
|
| 11 |
+
*shared lock* ownership mode. Multiple execution agents can
|
| 12 |
+
simultaneously hold a shared lock ownership of a shared mutex type. But
|
| 13 |
+
no execution agent shall hold a shared lock while another execution
|
| 14 |
+
agent holds an exclusive lock on the same shared mutex type, and
|
| 15 |
+
vice-versa. The maximum number of execution agents which can share a
|
| 16 |
+
shared lock on a single shared mutex type is unspecified, but shall be
|
| 17 |
+
at least 10000. If more than the maximum number of execution agents
|
| 18 |
+
attempt to obtain a shared lock, the excess execution agents shall block
|
| 19 |
+
until the number of shared locks are reduced below the maximum amount by
|
| 20 |
+
other execution agents releasing their shared lock.
|
| 21 |
+
|
| 22 |
+
The expression `m.lock_shared()` shall be well-formed and have the
|
| 23 |
+
following semantics:
|
| 24 |
+
|
| 25 |
+
*Requires:* The calling thread has no ownership of the mutex.
|
| 26 |
+
|
| 27 |
+
*Effects:* Blocks the calling thread until shared ownership of the mutex
|
| 28 |
+
can be obtained for the calling thread. If an exception is thrown then a
|
| 29 |
+
shared lock shall not have been acquired for the current thread.
|
| 30 |
+
|
| 31 |
+
*Postconditions:* The calling thread has a shared lock on the mutex.
|
| 32 |
+
|
| 33 |
+
*Return type:* `void`.
|
| 34 |
+
|
| 35 |
+
*Synchronization:* Prior `unlock()` operations on the same object shall
|
| 36 |
+
synchronize with ([[intro.multithread]]) this operation.
|
| 37 |
+
|
| 38 |
+
*Throws:* `system_error` when an exception is
|
| 39 |
+
required ([[thread.req.exception]]).
|
| 40 |
+
|
| 41 |
+
*Error conditions:*
|
| 42 |
+
|
| 43 |
+
- `operation_not_permitted` — if the thread does not have the privilege
|
| 44 |
+
to perform the operation.
|
| 45 |
+
- `resource_deadlock_would_occur` — if the implementation detects that a
|
| 46 |
+
deadlock would occur.
|
| 47 |
+
|
| 48 |
+
The expression `m.unlock_shared()` shall be well-formed and have the
|
| 49 |
+
following semantics:
|
| 50 |
+
|
| 51 |
+
*Requires:* The calling thread shall hold a shared lock on the mutex.
|
| 52 |
+
|
| 53 |
+
*Effects:* Releases a shared lock on the mutex held by the calling
|
| 54 |
+
thread.
|
| 55 |
+
|
| 56 |
+
*Return type:* `void`.
|
| 57 |
+
|
| 58 |
+
*Synchronization:* This operation synchronizes
|
| 59 |
+
with ([[intro.multithread]]) subsequent `lock()` operations that obtain
|
| 60 |
+
ownership on the same object.
|
| 61 |
+
|
| 62 |
+
*Throws:* Nothing.
|
| 63 |
+
|
| 64 |
+
The expression `m.try_lock_shared()` shall be well-formed and have the
|
| 65 |
+
following semantics:
|
| 66 |
+
|
| 67 |
+
*Requires:* The calling thread has no ownership of the mutex.
|
| 68 |
+
|
| 69 |
+
*Effects:* Attempts to obtain shared ownership of the mutex for the
|
| 70 |
+
calling thread without blocking. If shared ownership is not obtained,
|
| 71 |
+
there is no effect and `try_lock_shared()` immediately returns. An
|
| 72 |
+
implementation may fail to obtain the lock even if it is not held by any
|
| 73 |
+
other thread.
|
| 74 |
+
|
| 75 |
+
*Return type:* `bool`.
|
| 76 |
+
|
| 77 |
+
*Returns:* `true` if the shared ownership lock was acquired, `false`
|
| 78 |
+
otherwise.
|
| 79 |
+
|
| 80 |
+
*Synchronization:* If `try_lock_shared()` returns `true`, prior
|
| 81 |
+
`unlock()` operations on the same object synchronize
|
| 82 |
+
with ([[intro.multithread]]) this operation.
|
| 83 |
+
|
| 84 |
+
*Throws:* Nothing.
|
| 85 |
+
|
| 86 |
+
##### Class shared_mutex <a id="thread.sharedmutex.class">[[thread.sharedmutex.class]]</a>
|
| 87 |
+
|
| 88 |
+
``` cpp
|
| 89 |
+
namespace std {
|
| 90 |
+
class shared_mutex {
|
| 91 |
+
public:
|
| 92 |
+
shared_mutex();
|
| 93 |
+
~shared_mutex();
|
| 94 |
+
|
| 95 |
+
shared_mutex(const shared_mutex&) = delete;
|
| 96 |
+
shared_mutex& operator=(const shared_mutex&) = delete;
|
| 97 |
+
|
| 98 |
+
// Exclusive ownership
|
| 99 |
+
void lock(); // blocking
|
| 100 |
+
bool try_lock();
|
| 101 |
+
void unlock();
|
| 102 |
+
|
| 103 |
+
// Shared ownership
|
| 104 |
+
void lock_shared(); // blocking
|
| 105 |
+
bool try_lock_shared();
|
| 106 |
+
void unlock_shared();
|
| 107 |
+
|
| 108 |
+
using native_handle_type = implementation-defined; // See~[thread.req.native]
|
| 109 |
+
native_handle_type native_handle(); // See~[thread.req.native]
|
| 110 |
+
};
|
| 111 |
+
}
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
The class `shared_mutex` provides a non-recursive mutex with shared
|
| 115 |
+
ownership semantics.
|
| 116 |
+
|
| 117 |
+
The class `shared_mutex` shall satisfy all of the shared mutex
|
| 118 |
+
requirements ([[thread.sharedmutex.requirements]]). It shall be a
|
| 119 |
+
standard-layout class (Clause [[class]]).
|
| 120 |
+
|
| 121 |
+
The behavior of a program is undefined if:
|
| 122 |
+
|
| 123 |
+
- it destroys a `shared_mutex` object owned by any thread,
|
| 124 |
+
- a thread attempts to recursively gain any ownership of a
|
| 125 |
+
`shared_mutex`, or
|
| 126 |
+
- a thread terminates while possessing any ownership of a
|
| 127 |
+
`shared_mutex`.
|
| 128 |
+
|
| 129 |
+
`shared_mutex` may be a synonym for `shared_timed_mutex`.
|
| 130 |
+
|