算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
rust-concurrency-primitives【设计与创意】Design and review thread-based Rust concurrency with explicit ownership, sharing, and synchronization choices. Use when writing, refactoring, or reviewing threads, scoped threads, channels, Arc, Mutex, RwLock, Condvar, atomics, OnceLock, LazyLock, Send, Sync, deadlocks, or shared state.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this skill to design thread-based Rust concurrency with explicit ownership, sharing, and synchronization. Prefer the simplest primitive that matches the coordination requirement before adding shared mutable state.
std::thread::scope when child threads can borrow stack data and must
finish before the function returns.Arc<Mutex<T>> or
Arc<RwLock<T>> only when shared state is the clearer model.OnceLock or LazyLock for thread-safe one-time initialization instead
of ad hoc global mutable state.SeqCst by default until a weaker
ordering is justified and documented.Read references/threading-shared-state.md before introducing a new shared
state primitive or reviewing deadlock-prone code.
| Need | Primitive |
|---|---|
| Borrow local data into short-lived threads | std::thread::scope |
| Transfer work or results | std::sync::mpsc or project channel crate |
| Shared read/write state | Arc<Mutex<T>> |
| Many readers, rare writers | Arc<RwLock<T>> |
| Wait for condition changes | Condvar with Mutex |
| One-time global initialization | LazyLock or OnceLock |
| Counters, flags, lock-free coordination | std::sync::atomic |
Send for values crossing thread boundaries and Sync for shared
references used from multiple threads.PoisonError::into_inner.Arc::clone(&value) over value.clone() when the cloned value is an
ownership handle and readability matters.