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/sys/common | |
| 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/sys/common')
| -rw-r--r-- | src/libstd/sys/common/mutex.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libstd/sys/common/mutex.rs b/src/libstd/sys/common/mutex.rs index 5a6dfe7fb1a..7a2183c522f 100644 --- a/src/libstd/sys/common/mutex.rs +++ b/src/libstd/sys/common/mutex.rs @@ -27,6 +27,12 @@ impl Mutex { /// first used with any of the functions below. pub const fn new() -> Mutex { Mutex(imp::Mutex::new()) } + /// Prepare the mutex for use. + /// + /// This should be called once the mutex is at a stable memory address. + #[inline] + pub unsafe fn init(&mut self) { self.0.init() } + /// Locks the mutex blocking the current thread until it is available. /// /// Behavior is undefined if the mutex has been moved between this and any |
