Files
rust/src/libstd
bors 20dc0c5070 Auto merge of #54174 - parched:park, r=alexcrichton
Fix `thread` `park`/`unpark` synchronization

Previously the code below would not be guaranteed to exit when the
second unpark took the `return, // already unparked` path because there
was no write to synchronize with a read in `park`.

EDIT: doesn't actually require third thread
```
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread::{current, spawn, park};

static FLAG: AtomicBool = AtomicBool::new(false);

fn main() {
    let thread_0 = current();
    spawn(move || {
        thread_0.unpark();
        FLAG.store(true, Ordering::Relaxed);
        thread_0.unpark();
    });

    while !FLAG.load(Ordering::Relaxed) {
        park();
    }
}
```

I have some other ideas on how to improve the performance of `park` and `unpark` using fences, avoiding any atomic RMW when the state is already `NOTIFIED`, and also how to avoid calling `notify_one` without the mutex locked. But I need to write some micro benchmarks first, so I'll submit those changes at a later date if they prove to be faster.

Fixes https://github.com/rust-lang/rust/issues/53366 I hope.
2018-09-19 17:08:28 +00:00
..
2018-09-06 23:32:30 +02:00
2018-09-04 13:22:08 -06:00
2018-07-30 18:18:23 +02:00
2018-09-04 13:22:08 -06:00
2018-09-01 06:57:58 +02:00
2018-08-23 23:50:05 +02:00
2018-08-19 17:41:28 +02:00
2018-05-16 19:11:31 +02:00
2018-09-01 06:57:58 +02:00
2018-07-10 20:35:36 +02:00
2018-05-28 18:24:01 -06:00