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
//! Threads demo.
//!
//! This program spawns two threads. One does a `dbg` that prints
//! even numbers, the other does a `dbg` that prints odd numbers.
//!
//! Comment out the `use atomic_dbg::dbg;` line to use `std::dbg`. Run
//! it that way enough times, and you'll see the output of the two
//! threads interleave.
//!
//! std uses a `StderrLock`, so the interleaving only happens at line
//! boundaries. But if there's any non-Rust code in the process
//! printing to stderr from other threads, it could be interleaved
//! in the middle of a line.
//!
//! Uncomment that line to re-enable atomic-dbg and
//! the output will not be interleaved. Each thread does a single
//! atomic `write` call.
use dbg;
use thread;