diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2016-05-25 05:44:28 +0100 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2016-06-02 13:31:01 +0100 |
| commit | d73f5e65ecbcb6a0acb908b54226edfccf47eccc (patch) | |
| tree | b65444fe5785dbd66b4e04ff14c2575ad475407b /src/libstd/sync | |
| parent | eea4f0c24893d3b5bffec067e6051eb0b5106748 (diff) | |
| download | rust-d73f5e65ecbcb6a0acb908b54226edfccf47eccc.tar.gz rust-d73f5e65ecbcb6a0acb908b54226edfccf47eccc.zip | |
Fix undefined behavior when re-locking a mutex from the same thread
The only applies to pthread mutexes. We solve this by creating the mutex with the PTHREAD_MUTEX_NORMAL type, which guarantees that re-locking from the same thread will deadlock.
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/mutex.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 90cc79dad66..e53a97eccdf 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -190,10 +190,14 @@ impl<T> Mutex<T> { /// Creates a new mutex in an unlocked state ready for use. #[stable(feature = "rust1", since = "1.0.0")] pub fn new(t: T) -> Mutex<T> { - Mutex { + let mut m = Mutex { inner: box StaticMutex::new(), data: UnsafeCell::new(t), + }; + unsafe { + m.inner.lock.init(); } + m } } |
