rust/src
bors 3f111c166a Auto merge of #2114 - cbeuw:shim-rmw, r=RalfJung
Use atomic RMW for `{mutex, rwlock, cond, srwlock}_get_or_create_id` functions

This is required for #1963

`{mutex, rwlock, cond, srwlock}_get_or_create_id()` currently checks whether an ID field is 0 using an atomic read, allocate one and get a new ID if it is, then write it in a separate atomic write. This is fine without weak memory. For instance, in `pthread_mutex_lock` which may be called by two threads concurrently, only one thread can read 0, create and then write a new ID, the later-run thread will always see the newly created ID and never 0.
```rust
    fn pthread_mutex_lock(&mut self, mutex_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
        let this = self.eval_context_mut();

        let kind = mutex_get_kind(this, mutex_op)?.check_init()?;
        let id = mutex_get_or_create_id(this, mutex_op)?;
        let active_thread = this.get_active_thread();
```

However, with weak memory behaviour, both threads may read 0: the first thread has to see 0 because nothing else was written to it, and the second thread is not guaranteed to observe the latest value, causing a duplicate mutex to be created and both threads "successfully" acquiring the lock at the same time.

This is a pretty typical pattern requiring the use of atomic RMWs. RMW *always* reads the latest value in a location, so only one thread can create the new mutex and ID, all others scheduled later will see the new ID.
2022-05-13 19:04:59 +00:00
..
bin when MIRI_LOG is set, set RUSTC_LOG_ENTRY_EXIT 2022-05-11 10:04:30 +02:00
helpers Replace as casts in llvm.x86.addcarry.64 implementation 2022-04-30 10:33:55 -07:00
shims Auto merge of #2114 - cbeuw:shim-rmw, r=RalfJung 2022-05-13 19:04:59 +00:00
data_race.rs Move and rename offset_and_layout_to_place to deref_operand_and_offset 2022-05-13 18:42:53 +01:00
diagnostics.rs test for "erroneous constant used" post-monomorphization error 2022-05-08 17:56:09 +02:00
eval.rs Rename flag, datastructure and messaging around muting stdout and stderr 2022-04-26 09:33:20 +00:00
helpers.rs Auto merge of #2114 - cbeuw:shim-rmw, r=RalfJung 2022-05-13 19:04:59 +00:00
intptrcast.rs avoid into_pointer_or_addr and into_parts in visit_freeze_sensitive 2022-04-20 08:40:19 -04:00
lib.rs rustup 2022-05-06 17:28:01 +02:00
machine.rs rustup 2022-05-12 19:01:04 +02:00
mono_hash_map.rs adjust Miri to Pointer type overhaul 2021-07-16 10:10:12 +02:00
operator.rs rustup 2022-04-09 09:41:29 -04:00
range_map.rs Resolve clippy::needless_return 2022-04-29 15:53:48 -07:00
stacked_borrows.rs Resolve clippy::clone_on_copy 2022-04-29 15:37:35 -07:00
sync.rs Inline _create() calls and add assertions 2022-05-12 21:06:17 +01:00
thread.rs Resolve clippy::useless_conversion 2022-04-29 16:02:11 -07:00
vector_clock.rs remove no longer needed imports 2022-04-09 11:32:49 -04:00