{"id":26953905,"url":"https://github.com/zesterer/spin-rs","last_synced_at":"2026-01-15T22:18:34.843Z","repository":{"id":18490894,"uuid":"21686666","full_name":"zesterer/spin-rs","owner":"zesterer","description":"Spin-based synchronization primitives","archived":false,"fork":false,"pushed_at":"2025-04-01T22:06:22.000Z","size":316,"stargazers_count":530,"open_issues_count":12,"forks_count":94,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-15T00:14:39.445Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zesterer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-07-10T08:36:25.000Z","updated_at":"2025-05-10T10:35:50.000Z","dependencies_parsed_at":"2024-01-18T04:07:04.865Z","dependency_job_id":"b193f987-e9fe-4188-84fb-4447bdd9cf5f","html_url":"https://github.com/zesterer/spin-rs","commit_stats":{"total_commits":285,"total_committers":48,"mean_commits":5.9375,"dds":0.6175438596491227,"last_synced_commit":"1f2e06c9f9d22b234776849c65e313f583ddfade"},"previous_names":["mvdnes/spinlock-rs","zesterer/spin-rs","mvdnes/spin-rs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zesterer%2Fspin-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zesterer%2Fspin-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zesterer%2Fspin-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zesterer%2Fspin-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zesterer","download_url":"https://codeload.github.com/zesterer/spin-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249206,"owners_count":22039029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-04-03T02:00:12.823Z","updated_at":"2026-01-15T22:18:34.824Z","avatar_url":"https://github.com/zesterer.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# spin-rs\n\n[![Crates.io version](https://img.shields.io/crates/v/spin.svg)](https://crates.io/crates/spin)\n[![docs.rs](https://docs.rs/spin/badge.svg)](https://docs.rs/spin/)\n[![Build Status](https://github.com/zesterer/spin-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/zesterer/spin-rs/actions)\n\nSpin-based synchronization primitives.\n\nThis crate provides [spin-based](https://en.wikipedia.org/wiki/Spinlock)\nversions of the primitives in `std::sync`. Because synchronization is done\nthrough spinning, the primitives are suitable for use in `no_std` environments.\n\nBefore deciding to use `spin`, we recommend reading\n[this superb blog post](https://matklad.github.io/2020/01/02/spinlocks-considered-harmful.html)\nby [@matklad](https://github.com/matklad/) that discusses the pros and cons of\nspinlocks. If you have access to `std`, it's likely that the primitives in\n`std::sync` will serve you better except in very specific circumstances.\n\n## Features\n\n- `Mutex`, `RwLock`, `Once`, `Lazy` and `Barrier` equivalents\n- Support for `no_std` environments\n- [`lock_api`](https://crates.io/crates/lock_api) compatibility\n- Upgradeable `RwLock` guards\n- Guards can be sent and shared between threads\n- Guard leaking\n- Ticket locks\n- Different strategies for dealing with contention\n\n## Usage\n\nInclude the following under the `[dependencies]` section in your `Cargo.toml` file.\n\n```toml\nspin = \"x.y\"\n```\n\n## Example\n\nWhen calling `lock` on a `Mutex` you will get a guard value that provides access\nto the data. When this guard is dropped, the mutex will become available again.\n\n```rust\nextern crate spin;\nuse std::{sync::Arc, thread};\n\nfn main() {\n    let counter = Arc::new(spin::Mutex::new(0));\n\n    let thread = thread::spawn({\n        let counter = counter.clone();\n        move || {\n            for _ in 0..100 {\n                *counter.lock() += 1;\n            }\n        }\n    });\n\n    for _ in 0..100 {\n        *counter.lock() += 1;\n    }\n\n    thread.join().unwrap();\n\n    assert_eq!(*counter.lock(), 200);\n}\n```\n\n## Feature flags\n\nThe crate comes with a few feature flags that you may wish to use.\n\n- `mutex` enables the `Mutex` type.\n\n- `spin_mutex` enables the `SpinMutex` type.\n\n- `ticket_mutex` enables the `TicketMutex` type.\n\n- `use_ticket_mutex` switches to a ticket lock for the implementation of `Mutex`. This\n  is recommended only on targets for which ordinary spinning locks perform very badly\n  because it will change the implementation used by other crates that depend on `spin`.\n\n- `rwlock` enables the `RwLock` type.\n\n- `once` enables the `Once` type.\n\n- `lazy` enables the `Lazy` type.\n\n- `barrier` enables the `Barrier` type.\n\n- `lock_api` enables support for [`lock_api`](https://crates.io/crates/lock_api)\n\n- `std` enables support for thread yielding instead of spinning.\n\n- `portable-atomic` enables usage of the `portable-atomic` crate\n  to support platforms without native atomic operations (Cortex-M0, etc.).\n  The `portable_atomic_unsafe_assume_single_core` or `critical-section` feature\n  of `portable-atomic` crate must also be set by the final binary crate.\n  See the documentation for the `portable-atomic` crate for more information\n  with some requirements for no-std build:\n  https://github.com/taiki-e/portable-atomic#optional-features\n\n## Remarks\n\nIt is often desirable to have a lock shared between threads. Wrapping the lock in an\n`std::sync::Arc` is route through which this might be achieved.\n\nLocks provide zero-overhead access to their data when accessed through a mutable\nreference by using their `get_mut` methods.\n\nThe behaviour of these lock is similar to their namesakes in `std::sync`. they\ndiffer on the following:\n\n- Locks will not be poisoned in case of failure.\n- Threads will not yield to the OS scheduler when encounter a lock that cannot be\n  accessed. Instead, they will 'spin' in a busy loop until the lock becomes available.\n\nMany of the feature flags listed above are enabled by default. If you're writing a\nlibrary, we recommend disabling those that you don't use to avoid increasing compilation\ntime for your crate's users. You can do this like so:\n\n```\n[dependencies]\nspin = { version = \"x.y\", default-features = false, features = [...] }\n```\n\n## Minimum Safe Rust Version (MSRV)\n\nThis crate is guaranteed to compile on a Minimum Safe Rust Version (MSRV) of 1.60.0 and above.\nThis version will not be changed without a minor version bump.\n\n## License\n\n`spin` is distributed under the MIT License, (See `LICENSE`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzesterer%2Fspin-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzesterer%2Fspin-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzesterer%2Fspin-rs/lists"}