1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Example demonstrating usage of the `SpinLock` from the `axiom-spinlock` crate.
//!
//! This program spawns 100 threads, each incrementing a shared counter
//! a million times. The counter is protected by a `SpinLock<i64>` to ensure
//! safe concurrent mutation without data races.
use SpinLock;
use thread;
// Shared static spinlock protecting a 64-bit counter.
static Q: = new;
/// Increment the global counter one million times.
/// Each increment safely acquires the lock before modifying the value.