File tree Expand file tree Collapse file tree 3 files changed +5
-12
lines changed Expand file tree Collapse file tree 3 files changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -1281,9 +1281,7 @@ const F: &'static C = &D; // error
12811281```
12821282
12831283This is because cell types do operations that are not thread-safe. Due to this,
1284- they don't implement Sync and thus can't be placed in statics. In this
1285- case, `StaticMutex` would work just fine, but it isn't stable yet:
1286- https://doc.rust-lang.org/nightly/std/sync/struct.StaticMutex.html
1284+ they don't implement Sync and thus can't be placed in statics.
12871285
12881286However, if you still wish to use these types, you can achieve this by an unsafe
12891287wrapper:
Original file line number Diff line number Diff line change 3131// initialization closure panics, the Once enters a "poisoned" state which means
3232// that all future calls will immediately panic as well.
3333//
34- // So to implement this, one might first reach for a `StaticMutex`, but those
35- // unfortunately need to be deallocated (e.g. call `destroy()`) to free memory
36- // on all OSes (some of the BSDs allocate memory for mutexes). It also gets a
37- // lot harder with poisoning to figure out when the mutex needs to be
38- // deallocated because it's not after the closure finishes, but after the first
39- // successful closure finishes.
34+ // So to implement this, one might first reach for a `Mutex`, but those cannot
35+ // be put into a `static`. It also gets a lot harder with poisoning to figure
36+ // out when the mutex needs to be deallocated because it's not after the closure
37+ // finishes, but after the first successful closure finishes.
4038//
4139// All in all, this is instead implemented with atomics and lock-free
4240// operations! Whee! Each `Once` has one word of atomic state, and this state is
Original file line number Diff line number Diff line change @@ -49,9 +49,6 @@ impl Mutex {
4949 // references, we instead create the mutex with type
5050 // PTHREAD_MUTEX_NORMAL which is guaranteed to deadlock if we try to
5151 // re-lock it from the same thread, thus avoiding undefined behavior.
52- //
53- // We can't do anything for StaticMutex, but that type is deprecated
54- // anyways.
5552 let mut attr: libc:: pthread_mutexattr_t = mem:: uninitialized ( ) ;
5653 let r = libc:: pthread_mutexattr_init ( & mut attr) ;
5754 debug_assert_eq ! ( r, 0 ) ;
You can’t perform that action at this time.
0 commit comments