{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiajilzcolt3cxlrkljkomdv47yklkdbeeqdgyac3k7qpw3h5vv5re",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mgdfk4lkvqg2"
  },
  "path": "/t/idea-lock-free-std-collection/24056#post_1",
  "publishedAt": "2026-03-05T13:28:20.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "Idea : A lock-free version of the `std` collection.\n\nMotivation :\n\n  * Lock free performance is generally superior to mutex/rwlock based synchronization.\n  * The code becomes cleaner because there is no need to manually invoke mutexes or locks, one simply uses `std::collection::{LockfreeVec, LockfreeMap}` and `Arc::new(LockfreeVec::new())`.\n  * The user is safe from deadlock \"footguns.\"\n\n\n\nReason for Inclusion in `std` :\n\n  * To ensure ecosystem interoperability. If implemented in third party libraries, Library A might use Lock-free Library A, while Library B uses Lock-free Library B. If I use both libraries and need to pass the output of Library A (returning Lock-free Type A) to Library B (expecting Lock-free Type B), they become incompatible.\n\n\n\nBenefits : It offers the same `interoperability` benefits as the current `Vector` implementation, where all users are compatible with one another. The usage is also significantly simpler than `Arc<Mutex<Vec>>` because it eliminates the need for locking, which can cause deadlocks while this approach is `deadlock free`.\n\nFor example :\n\n\n    let a = Arc::new(LockfreeVec::with_capacity(10));\n    let b = a.clone();\n\n    thread::spawn(move || {\n        b.push(\"input\");\n    }).join().unwrap();\n",
  "title": "Idea : Lock Free STD Collection"
}