about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-09-19 17:08:28 +0000
committerbors <bors@rust-lang.org>2018-09-19 17:08:28 +0000
commit20dc0c50704ba1fc8c56a88ae2bf05ddb3e419bc (patch)
treef0703f76908d464550e18c0afa4a22f76d6ce400 /src/libsyntax/parse
parent4f3ff5a97bcd2d05ee0c768122752dc74f96ccc3 (diff)
parenta3b87058e7e4e590ac2c00215785e62aa5f7bec5 (diff)
downloadrust-20dc0c50704ba1fc8c56a88ae2bf05ddb3e419bc.tar.gz
rust-20dc0c50704ba1fc8c56a88ae2bf05ddb3e419bc.zip
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.
Diffstat (limited to 'src/libsyntax/parse')
0 files changed, 0 insertions, 0 deletions