{"id":18054105,"url":"https://github.com/mbuesch/rangelockrs","last_synced_at":"2026-07-09T15:31:38.622Z","repository":{"id":153373919,"uuid":"494814259","full_name":"mbuesch/rangelockrs","owner":"mbuesch","description":"Rust: Range lock for std::vec::Vec","archived":false,"fork":false,"pushed_at":"2025-11-06T19:05:54.000Z","size":157,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-06-16T08:05:04.562Z","etag":null,"topics":["lock","multithreading","mutex","vec"],"latest_commit_sha":null,"homepage":"https://bues.ch/cgit/rangelockrs.git/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbuesch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-05-21T14:59:30.000Z","updated_at":"2025-11-06T19:05:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"47ff815f-8296-4333-ae9c-d26af0fd22ae","html_url":"https://github.com/mbuesch/rangelockrs","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/mbuesch/rangelockrs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuesch%2Frangelockrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuesch%2Frangelockrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuesch%2Frangelockrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuesch%2Frangelockrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbuesch","download_url":"https://codeload.github.com/mbuesch/rangelockrs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbuesch%2Frangelockrs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35304874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-09T02:00:07.329Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lock","multithreading","mutex","vec"],"created_at":"2024-10-31T00:09:17.826Z","updated_at":"2026-07-09T15:31:38.611Z","avatar_url":"https://github.com/mbuesch.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# range-lock - Multithread range lock for Vec\n\n[Project home](https://bues.ch/)\n\n[Git repository](https://bues.ch/cgit/rangelockrs.git)\n\n[Github repository](https://github.com/mbuesch/rangelockrs)\n\nThis crate provides locks/mutexes for multi-threaded access to a single `Vec\u003cT\u003e` instance.\n\nAny thread can request exclusive access to a slice of the `Vec`.\nSuch access is granted, if no other thread is simultaneously holding the permission to access an overlapping slice.\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nrange-lock = \"0.2\"\n```\n\n## VecRangeLock example usage\n\nGeneral purpose `VecRangeLock`:\n\n```rust\nuse range_lock::VecRangeLock;\nuse std::sync::Arc;\nuse std::thread;\n\nlet lock = Arc::new(VecRangeLock::new(vec![1, 2, 3, 4, 5]));\n\nthread::spawn(move || {\n    let mut guard = lock.try_lock(2..4).expect(\"Failed to lock range 2..4\");\n    assert_eq!(guard[0], 3);\n    guard[0] = 10;\n});\n```\n\n## RepVecRangeLock example usage\n\nThe `RepVecRangeLock` is a restricted range lock, that provides access to interleaved patterns of slices to the threads.\n\nLocking a `RepVecRangeLock` is more lightweight than locking a `VecRangeLock`.\nThe threads can not freely choose slice ranges, but only choose a repeating slice pattern by specifying a pattern offset.\n\nPlease see the example below.\n\n```rust\nuse range_lock::RepVecRangeLock;\nuse std::sync::Arc;\nuse std::thread;\n\nlet data = vec![1, 2, 3,  // \u003c- cycle 0\n                4, 5, 6]; // \u003c- cycle 1\n//              ^  ^  ^\n//              |  |  |\n//              |  |  offset-2\n//       offset-0  offset-1\n\nlet lock = Arc::new(RepVecRangeLock::new(data,\n                                         1,    // slice_len: Each slice has 1 element.\n                                         3));  // cycle_len: Each cycle has 3 slices (offsets).\nthread::spawn(move || {\n    // Lock slice offset 1:\n    let mut guard = lock.try_lock(1).expect(\"Failed to lock offset.\");\n\n    assert_eq!(guard[0][0], 2);     // Cycle 0, Slice element 0\n    assert_eq!(guard[1][0], 5);     // Cycle 1, Slice element 0\n\n    guard[0][0] = 20;               // Cycle 0, Slice element 0\n    guard[1][0] = 50;               // Cycle 1, Slice element 0\n});\n```\n\n## TODOs for future releases\n\nThe following new features might be candidates for future releases:\n\n- Sleeping lock, in case of lock contention.\n- Add support for arrays.\n\n## License\n\nCopyright (c) 2021-2025 Michael Büsch \u003cm@bues.ch\u003e\n\nLicensed under the Apache License version 2.0 or the MIT license, at your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbuesch%2Frangelockrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbuesch%2Frangelockrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbuesch%2Frangelockrs/lists"}