File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed
includes/standard-library
rules/donotdestroyamutexwhileitislocked Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ constexpr try_to_lock_t try_to_lock{};
2323class mutex {
2424public:
2525 constexpr mutex () noexcept ;
26- ~mutex ();
26+ ~mutex () = default ;
2727 mutex (const mutex &) = delete ;
2828 mutex &operator =(const mutex &) = delete ;
2929 void lock ();
@@ -62,15 +62,19 @@ template <class Mutex>
6262void swap (unique_lock<Mutex> &x, unique_lock<Mutex> &y) noexcept ;
6363
6464template <class _Lock0 , class _Lock1 , class ... _LockN>
65- void lock (_Lock0 &_Lk0, _Lock1 &_Lk1, _LockN &..._LkN) { }
65+ void lock (_Lock0 &_Lk0, _Lock1 &_Lk1, _LockN &..._LkN) {}
6666
6767template <typename Mutex> class lock_guard {
6868public:
6969 typedef Mutex mutex_type;
7070
71- explicit lock_guard (mutex_type &__m);
71+ explicit lock_guard (mutex_type &__m) : _m(__m) { _m. lock (); }
7272 lock_guard (const lock_guard &) = delete ;
7373 lock_guard &operator =(const lock_guard &) = delete ;
74+ ~lock_guard () { _m.unlock (); }
75+
76+ private:
77+ mutex_type &_m;
7478};
7579
7680} // namespace std
Original file line number Diff line number Diff line change 1- | test.cpp:4:18:4:33 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:11:18:11:26 | call to ~mutex | destroyed |
21| test.cpp:4:18:4:33 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:11:18:11:26 | delete | destroyed |
3- | test.cpp:16:14:16:15 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:21:1:21:1 | call to ~mutex | destroyed |
42| test.cpp:16:14:16:15 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:21:1:21:1 | return ... | destroyed |
5- | test.cpp:94:8:94:23 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:10:34:10:42 | call to ~mutex | destroyed |
63| test.cpp:94:8:94:23 | call to mutex | Mutex used by thread potentially $@ while in use. | test.cpp:10:34:10:42 | delete | destroyed |
You can’t perform that action at this time.
0 commit comments