Aliasing-motivated concurrency optimizations

Aperta
#572 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

Start with the test0-test4 examples in the issue, then read the linked LLVM, C++, and concurrency references to understand the aliasing and ordering claims. Done would require a project-level decision about whether these executions should be allowed or forbidden; the payload names no repository files or runnable tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The following tests capture some of the interactions between aliasing and concurrency.
While the optimizations below may introduce a data-race, any such execution is undefined due to aliasing violations: they'd need to access memory through a reference that's not derived from the &mut.
I don't see any immediate harm in these being allowed, but I found these being allowed by Rust and LLVM-IR interesting, to say the least.

The comments capture what I believe is the "status-quo", everyone should decide for themselves whether they think those executions should be allowed or forbidden:

pub fn test0(b: &mut u32){
  loop {
     let a = AtomicU32::from_mut(b);
     if a.load(Ordering::Relaxed) != 0 { // may be downgraded to non-atomic access
        break;
     }
  }
  *b = 42;
}

pub fn test1(b: &mut u32) -> u32 {
  let x = *b;
  fence(Ordering::Release); // may be re-ordered above load; analogous for store-release
  x
}

pub fn test2(b: &mut u32) {
  *b = 42;
  fence(Ordering::Release); // may be re-ordered above store; analogous for store-release
}

pub fn test3(b: &mut u32) {
  fence(Ordering::Acquire); // analogous for load-acquire
  *b = 42; // may be re-ordered above fence
}

pub fn test4(b: &mut u32) -> u32 {
  fence(Ordering::Acquire); // analogous for load-acquire
  *b // may be re-ordered above fence
}

The examples above are very simple and don't involve allocation APIs.
The following references include many other examples, some of which may be interesting to adapt to Rust.
Particularly interesting are those involving concurrency and "lifetime start"/"end" (memory being allocated/deallocated).

Lingua principale
Nessun dato sulla lingua
Stelle
760
Fork
68
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/unsafe-code-guidelines

Tutte le issue di rust-lang/unsafe-code-guidelines

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.