FFORGE//RS
← Roadmap

rust / LEVEL 4

Two correct transfers, one deadlock

EST.45 MIN
01

THEORY / RETRIEVAL

What to restore

  • Recognize circular wait caused by request-dependent lock order
  • Handle same-resource and invalid-index cases before locking

Memory safety does not prevent deadlock

Mutex guards protect data races, but two threads can still wait forever when they acquire the same locks in opposite order. A stable global order removes the circular-wait condition for this lock set.

Validate before taking scarce resources

Self-transfers, invalid indices and invalid amounts should be rejected before acquiring locks. This keeps critical sections small and avoids trying to lock the same non-reentrant mutex twice.

CHECKPOINT

Threads transfer 0→1 and 1→0 concurrently. Which rule directly removes their circular wait?

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / DEBUGGING

Find and fix the defect

Repair `transfer`: reject invalid operations and acquire two account locks in a stable order while still applying debit and credit to the requested direction.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
1 / 64 KB
OUTPUT
Runner is waiting for a submission.