# XO0804: value read in one `Mutex.with` is written back in a later one

Warning. A value read (or derived) inside one `m.with(...)` is used inside a later `m.with(...)` on the same mutex, or a branch on it decides whether the later one runs. Another task may change the state between the two sections (check then act), so the write can overwrite a newer value. Do the read and the write in one `with`. See core 5.4.

## Example

```xo
struct B { n: Int }

fn bump(m: Mutex[Map[Str, B]]) {
  let b = m.with(fn(s) { s.get("k") ?? B{n: 0} })
  m.with(fn(var s) { s.put("k", b with {n: b.n + 1}) })
}
```

## Fix

```xo
struct B { n: Int }

fn bump(m: Mutex[Map[Str, B]]) {
  m.with(fn(var s) {
    let b = s.get("k") ?? B{n: 0}
    s.put("k", b with {n: b.n + 1})
  })
}
```

Run `xo explain XO0804` for this text in a terminal, or see
[section 10.6 of the specification](../../spec/core/#106-diagnostic-codes).

