tmp/tmp8wqwlc43/{from.md → to.md}
RENAMED
|
@@ -1,72 +1,72 @@
|
|
| 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
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 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
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
The expression `m.lock_shared()`
|
| 23 |
-
|
| 24 |
|
| 25 |
-
*
|
| 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
|
| 30 |
|
| 31 |
-
*
|
| 32 |
|
| 33 |
*Return type:* `void`.
|
| 34 |
|
| 35 |
-
*Synchronization:* Prior `unlock()` operations on the same object
|
| 36 |
-
synchronize with
|
| 37 |
|
| 38 |
*Throws:* `system_error` when an exception is
|
| 39 |
-
required
|
| 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()`
|
| 49 |
-
|
| 50 |
|
| 51 |
-
*
|
| 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
|
| 60 |
ownership on the same object.
|
| 61 |
|
| 62 |
*Throws:* Nothing.
|
| 63 |
|
| 64 |
-
The expression `m.try_lock_shared()`
|
| 65 |
following semantics:
|
| 66 |
|
| 67 |
-
*
|
| 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
|
|
@@ -77,15 +77,15 @@ other thread.
|
|
| 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
|
| 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:
|
|
@@ -93,32 +93,32 @@ namespace std {
|
|
| 93 |
~shared_mutex();
|
| 94 |
|
| 95 |
shared_mutex(const shared_mutex&) = delete;
|
| 96 |
shared_mutex& operator=(const shared_mutex&) = delete;
|
| 97 |
|
| 98 |
-
//
|
| 99 |
void lock(); // blocking
|
| 100 |
bool try_lock();
|
| 101 |
void unlock();
|
| 102 |
|
| 103 |
-
//
|
| 104 |
void lock_shared(); // blocking
|
| 105 |
bool try_lock_shared();
|
| 106 |
void unlock_shared();
|
| 107 |
|
| 108 |
-
using native_handle_type = implementation-defined;
|
| 109 |
-
native_handle_type native_handle();
|
| 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`
|
| 118 |
-
|
| 119 |
-
|
| 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
|
|
|
|
| 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 meet the requirements of mutex
|
| 5 |
+
types [[thread.mutex.requirements.mutex]] and additionally meet the
|
| 6 |
+
requirements set out below. In this description, `m` denotes an object
|
| 7 |
+
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 holds a shared lock while another execution agent
|
| 14 |
+
holds an exclusive lock on the same shared mutex type, and vice-versa.
|
| 15 |
+
The maximum number of execution agents which can share a shared lock on
|
| 16 |
+
a single shared mutex type is unspecified, but is at least 10000. If
|
| 17 |
+
more than the maximum number of execution agents attempt to obtain a
|
| 18 |
+
shared lock, the excess execution agents block until the number of
|
| 19 |
+
shared locks are reduced below the maximum amount by other execution
|
| 20 |
+
agents releasing their shared lock.
|
| 21 |
|
| 22 |
+
The expression `m.lock_shared()` is well-formed and has the following
|
| 23 |
+
semantics:
|
| 24 |
|
| 25 |
+
*Preconditions:* 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 has not been acquired for the current thread.
|
| 30 |
|
| 31 |
+
*Ensures:* 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
|
| 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()` is well-formed and has the following
|
| 49 |
+
semantics:
|
| 50 |
|
| 51 |
+
*Preconditions:* The calling thread holds 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()` is well-formed and has the
|
| 65 |
following semantics:
|
| 66 |
|
| 67 |
+
*Preconditions:* 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
|
|
|
|
| 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:
|
|
|
|
| 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` meets all of the shared mutex requirements
|
| 118 |
+
[[thread.sharedmutex.requirements]]. It is a standard-layout class
|
| 119 |
+
[[class.prop]].
|
| 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
|