AtomicBool

Struct AtomicBool 

Source
pub struct AtomicBool { /* private fields */ }
Expand description

Atomic boolean type.

Provides easy-to-use atomic operations with automatic memory ordering selection. All methods are thread-safe and can be shared across threads.

§Memory Ordering Strategy

This type uses carefully selected default memory orderings:

  • Read operations (load): Use Acquire ordering to ensure that all writes from other threads that happened before a Release store are visible after this load.

  • Write operations (store): Use Release ordering to ensure that all prior writes in this thread are visible to other threads that perform an Acquire load.

  • Read-Modify-Write operations (swap, compare_set, fetch_*): Use AcqRel ordering to combine both Acquire and Release semantics, ensuring proper synchronization in both directions.

  • CAS failure: Use Acquire ordering on failure to observe the actual value written by another thread.

These orderings provide a balance between performance and correctness for typical concurrent programming patterns.

§Features

  • Automatic memory ordering selection
  • Rich set of boolean-specific operations
  • Zero-cost abstraction with inline methods
  • Access to underlying type via inner() for advanced use cases

§Example

use prism3_rust_concurrent::atomic::AtomicBool;
use std::sync::Arc;
use std::thread;

let flag = Arc::new(AtomicBool::new(false));
let flag_clone = flag.clone();

let handle = thread::spawn(move || {
    flag_clone.store(true);
});

handle.join().unwrap();
assert_eq!(flag.load(), true);

§Author

Haixing Hu

Implementations§

Source§

impl AtomicBool

Source

pub const fn new(value: bool) -> Self

Creates a new atomic boolean.

§Parameters
  • value - The initial value.
§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
assert_eq!(flag.load(), false);
Examples found in repository?
examples/boolean_flag.rs (line 23)
18fn main() {
19    println!("=== Atomic Boolean Flag Example ===\n");
20
21    // Example 1: Simple flag
22    println!("1. Simple Flag:");
23    let flag = AtomicBool::new(false);
24    println!("   Initial value: {}", flag.load());
25
26    flag.store(true);
27    println!("   After set(true): {}", flag.load());
28
29    flag.fetch_not();
30    println!("   After negate: {}", flag.load());
31
32    // Example 2: One-time initialization
33    println!("\n2. One-time Initialization:");
34    let initialized = Arc::new(AtomicBool::new(false));
35    let mut handles = vec![];
36
37    for i in 0..5 {
38        let initialized = initialized.clone();
39        let handle = thread::spawn(move || {
40            if initialized.set_if_false(true).is_ok() {
41                println!("   Thread {} performed initialization", i);
42                thread::sleep(Duration::from_millis(100));
43            } else {
44                println!("   Thread {} skipped (already initialized)", i);
45            }
46        });
47        handles.push(handle);
48    }
49
50    for handle in handles {
51        handle.join().unwrap();
52    }
53
54    println!("   Final state: initialized = {}", initialized.load());
55
56    // Example 3: Producer-Consumer signaling
57    println!("\n3. Producer-Consumer Signaling:");
58    let ready = Arc::new(AtomicBool::new(false));
59    let data = Arc::new(AtomicBool::new(false));
60
61    let ready_clone = ready.clone();
62    let data_clone = data.clone();
63
64    // Producer thread
65    let producer = thread::spawn(move || {
66        println!("   Producer: preparing data...");
67        thread::sleep(Duration::from_millis(100));
68        data_clone.store(true);
69        ready_clone.store(true);
70        println!("   Producer: data ready!");
71    });
72
73    // Consumer thread
74    let consumer = thread::spawn(move || {
75        println!("   Consumer: waiting for data...");
76        while !ready.load() {
77            thread::yield_now();
78        }
79        println!("   Consumer: received data = {}", data.load());
80    });
81
82    producer.join().unwrap();
83    consumer.join().unwrap();
84
85    // Example 4: Toggle operations
86    println!("\n4. Toggle Operations:");
87    let flag = Arc::new(AtomicBool::new(false));
88    let mut handles = vec![];
89
90    for i in 0..10 {
91        let flag = flag.clone();
92        let handle = thread::spawn(move || {
93            for _ in 0..10 {
94                flag.fetch_not();
95            }
96            println!("   Thread {} completed 10 toggles", i);
97        });
98        handles.push(handle);
99    }
100
101    for handle in handles {
102        handle.join().unwrap();
103    }
104
105    println!("   Final state: {} (after 100 toggles)", flag.load());
106
107    println!("\n=== Example completed ===");
108}
Source

pub fn load(&self) -> bool

Gets the current value.

§Memory Ordering

Uses Acquire ordering. This ensures that:

  • All writes from other threads that happened before a Release store are visible after this load.
  • Forms a synchronizes-with relationship with Release stores.
  • Prevents reordering of subsequent reads/writes before this load.

This is appropriate for reading shared state that may have been modified by other threads.

§Returns

The current value.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(true);
assert_eq!(flag.load(), true);
Examples found in repository?
examples/boolean_flag.rs (line 24)
18fn main() {
19    println!("=== Atomic Boolean Flag Example ===\n");
20
21    // Example 1: Simple flag
22    println!("1. Simple Flag:");
23    let flag = AtomicBool::new(false);
24    println!("   Initial value: {}", flag.load());
25
26    flag.store(true);
27    println!("   After set(true): {}", flag.load());
28
29    flag.fetch_not();
30    println!("   After negate: {}", flag.load());
31
32    // Example 2: One-time initialization
33    println!("\n2. One-time Initialization:");
34    let initialized = Arc::new(AtomicBool::new(false));
35    let mut handles = vec![];
36
37    for i in 0..5 {
38        let initialized = initialized.clone();
39        let handle = thread::spawn(move || {
40            if initialized.set_if_false(true).is_ok() {
41                println!("   Thread {} performed initialization", i);
42                thread::sleep(Duration::from_millis(100));
43            } else {
44                println!("   Thread {} skipped (already initialized)", i);
45            }
46        });
47        handles.push(handle);
48    }
49
50    for handle in handles {
51        handle.join().unwrap();
52    }
53
54    println!("   Final state: initialized = {}", initialized.load());
55
56    // Example 3: Producer-Consumer signaling
57    println!("\n3. Producer-Consumer Signaling:");
58    let ready = Arc::new(AtomicBool::new(false));
59    let data = Arc::new(AtomicBool::new(false));
60
61    let ready_clone = ready.clone();
62    let data_clone = data.clone();
63
64    // Producer thread
65    let producer = thread::spawn(move || {
66        println!("   Producer: preparing data...");
67        thread::sleep(Duration::from_millis(100));
68        data_clone.store(true);
69        ready_clone.store(true);
70        println!("   Producer: data ready!");
71    });
72
73    // Consumer thread
74    let consumer = thread::spawn(move || {
75        println!("   Consumer: waiting for data...");
76        while !ready.load() {
77            thread::yield_now();
78        }
79        println!("   Consumer: received data = {}", data.load());
80    });
81
82    producer.join().unwrap();
83    consumer.join().unwrap();
84
85    // Example 4: Toggle operations
86    println!("\n4. Toggle Operations:");
87    let flag = Arc::new(AtomicBool::new(false));
88    let mut handles = vec![];
89
90    for i in 0..10 {
91        let flag = flag.clone();
92        let handle = thread::spawn(move || {
93            for _ in 0..10 {
94                flag.fetch_not();
95            }
96            println!("   Thread {} completed 10 toggles", i);
97        });
98        handles.push(handle);
99    }
100
101    for handle in handles {
102        handle.join().unwrap();
103    }
104
105    println!("   Final state: {} (after 100 toggles)", flag.load());
106
107    println!("\n=== Example completed ===");
108}
Source

pub fn store(&self, value: bool)

Sets a new value.

§Memory Ordering

Uses Release ordering. This ensures that:

  • All prior writes in this thread are visible to other threads that perform an Acquire load.
  • Forms a synchronizes-with relationship with Acquire loads.
  • Prevents reordering of prior reads/writes after this store.

This is appropriate for publishing shared state to other threads.

§Parameters
  • value - The new value to set.
§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
flag.store(true);
assert_eq!(flag.load(), true);
Examples found in repository?
examples/boolean_flag.rs (line 26)
18fn main() {
19    println!("=== Atomic Boolean Flag Example ===\n");
20
21    // Example 1: Simple flag
22    println!("1. Simple Flag:");
23    let flag = AtomicBool::new(false);
24    println!("   Initial value: {}", flag.load());
25
26    flag.store(true);
27    println!("   After set(true): {}", flag.load());
28
29    flag.fetch_not();
30    println!("   After negate: {}", flag.load());
31
32    // Example 2: One-time initialization
33    println!("\n2. One-time Initialization:");
34    let initialized = Arc::new(AtomicBool::new(false));
35    let mut handles = vec![];
36
37    for i in 0..5 {
38        let initialized = initialized.clone();
39        let handle = thread::spawn(move || {
40            if initialized.set_if_false(true).is_ok() {
41                println!("   Thread {} performed initialization", i);
42                thread::sleep(Duration::from_millis(100));
43            } else {
44                println!("   Thread {} skipped (already initialized)", i);
45            }
46        });
47        handles.push(handle);
48    }
49
50    for handle in handles {
51        handle.join().unwrap();
52    }
53
54    println!("   Final state: initialized = {}", initialized.load());
55
56    // Example 3: Producer-Consumer signaling
57    println!("\n3. Producer-Consumer Signaling:");
58    let ready = Arc::new(AtomicBool::new(false));
59    let data = Arc::new(AtomicBool::new(false));
60
61    let ready_clone = ready.clone();
62    let data_clone = data.clone();
63
64    // Producer thread
65    let producer = thread::spawn(move || {
66        println!("   Producer: preparing data...");
67        thread::sleep(Duration::from_millis(100));
68        data_clone.store(true);
69        ready_clone.store(true);
70        println!("   Producer: data ready!");
71    });
72
73    // Consumer thread
74    let consumer = thread::spawn(move || {
75        println!("   Consumer: waiting for data...");
76        while !ready.load() {
77            thread::yield_now();
78        }
79        println!("   Consumer: received data = {}", data.load());
80    });
81
82    producer.join().unwrap();
83    consumer.join().unwrap();
84
85    // Example 4: Toggle operations
86    println!("\n4. Toggle Operations:");
87    let flag = Arc::new(AtomicBool::new(false));
88    let mut handles = vec![];
89
90    for i in 0..10 {
91        let flag = flag.clone();
92        let handle = thread::spawn(move || {
93            for _ in 0..10 {
94                flag.fetch_not();
95            }
96            println!("   Thread {} completed 10 toggles", i);
97        });
98        handles.push(handle);
99    }
100
101    for handle in handles {
102        handle.join().unwrap();
103    }
104
105    println!("   Final state: {} (after 100 toggles)", flag.load());
106
107    println!("\n=== Example completed ===");
108}
Source

pub fn swap(&self, value: bool) -> bool

Swaps the current value with a new value, returning the old value.

§Memory Ordering

Uses AcqRel ordering. This ensures that:

  • Acquire: All writes from other threads that happened before their Release operations are visible after this operation.
  • Release: All prior writes in this thread are visible to other threads that perform subsequent Acquire operations.

This provides full synchronization for read-modify-write operations.

§Parameters
  • value - The new value to swap in.
§Returns

The old value.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
let old = flag.swap(true);
assert_eq!(old, false);
assert_eq!(flag.load(), true);
Source

pub fn compare_set(&self, current: bool, new: bool) -> Result<(), bool>

Compares and sets the value atomically.

If the current value equals current, sets it to new and returns Ok(()). Otherwise, returns Err(actual) where actual is the current value.

§Memory Ordering
  • Success: Uses AcqRel ordering to ensure full synchronization when the exchange succeeds.
  • Failure: Uses Acquire ordering to observe the actual value written by another thread.

This pattern is essential for implementing lock-free algorithms where you need to retry based on the observed value.

§Parameters
  • current - The expected current value.
  • new - The new value to set if current matches.
§Returns

Ok(()) on success, or Err(actual) on failure.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
assert!(flag.compare_set(false, true).is_ok());
assert_eq!(flag.load(), true);

// Fails because current value is true, not false
assert!(flag.compare_set(false, false).is_err());
Source

pub fn compare_set_weak(&self, current: bool, new: bool) -> Result<(), bool>

Weak version of compare-and-set.

May spuriously fail even when the comparison succeeds. Should be used in a loop.

Uses AcqRel ordering on success and Acquire ordering on failure.

§Parameters
  • current - The expected current value.
  • new - The new value to set if current matches.
§Returns

Ok(()) on success, or Err(actual) on failure.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
let mut current = flag.load();
loop {
    match flag.compare_set_weak(current, true) {
        Ok(_) => break,
        Err(actual) => current = actual,
    }
}
assert_eq!(flag.load(), true);
Source

pub fn compare_and_exchange(&self, current: bool, new: bool) -> bool

Compares and exchanges the value atomically, returning the previous value.

If the current value equals current, sets it to new and returns the old value. Otherwise, returns the actual current value.

Uses AcqRel ordering on success and Acquire ordering on failure.

§Parameters
  • current - The expected current value.
  • new - The new value to set if current matches.
§Returns

The value before the operation.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
let prev = flag.compare_and_exchange(false, true);
assert_eq!(prev, false);
assert_eq!(flag.load(), true);
Source

pub fn compare_and_exchange_weak(&self, current: bool, new: bool) -> bool

Weak version of compare-and-exchange.

May spuriously fail even when the comparison succeeds. Should be used in a loop.

Uses AcqRel ordering on success and Acquire ordering on failure.

§Parameters
  • current - The expected current value.
  • new - The new value to set if current matches.
§Returns

The value before the operation.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
let mut current = flag.load();
loop {
    let prev = flag.compare_and_exchange_weak(current, true);
    if prev == current {
        break;
    }
    current = prev;
}
assert_eq!(flag.load(), true);
Source

pub fn fetch_set(&self) -> bool

Atomically sets the value to true, returning the old value.

§Memory Ordering

Uses AcqRel ordering (via swap). This ensures full synchronization with other threads for this read-modify-write operation.

§Returns

The old value before setting to true.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
let old = flag.fetch_set();
assert_eq!(old, false);
assert_eq!(flag.load(), true);
Source

pub fn fetch_clear(&self) -> bool

Atomically sets the value to false, returning the old value.

§Memory Ordering

Uses AcqRel ordering (via swap). This ensures full synchronization with other threads for this read-modify-write operation.

§Returns

The old value before setting to false.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(true);
let old = flag.fetch_clear();
assert_eq!(old, true);
assert_eq!(flag.load(), false);
Source

pub fn fetch_not(&self) -> bool

Atomically negates the value, returning the old value.

§Memory Ordering

Uses AcqRel ordering. This ensures full synchronization with other threads for this read-modify-write operation.

§Returns

The old value before negation.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
assert_eq!(flag.fetch_not(), false);
assert_eq!(flag.load(), true);
assert_eq!(flag.fetch_not(), true);
assert_eq!(flag.load(), false);
Examples found in repository?
examples/boolean_flag.rs (line 29)
18fn main() {
19    println!("=== Atomic Boolean Flag Example ===\n");
20
21    // Example 1: Simple flag
22    println!("1. Simple Flag:");
23    let flag = AtomicBool::new(false);
24    println!("   Initial value: {}", flag.load());
25
26    flag.store(true);
27    println!("   After set(true): {}", flag.load());
28
29    flag.fetch_not();
30    println!("   After negate: {}", flag.load());
31
32    // Example 2: One-time initialization
33    println!("\n2. One-time Initialization:");
34    let initialized = Arc::new(AtomicBool::new(false));
35    let mut handles = vec![];
36
37    for i in 0..5 {
38        let initialized = initialized.clone();
39        let handle = thread::spawn(move || {
40            if initialized.set_if_false(true).is_ok() {
41                println!("   Thread {} performed initialization", i);
42                thread::sleep(Duration::from_millis(100));
43            } else {
44                println!("   Thread {} skipped (already initialized)", i);
45            }
46        });
47        handles.push(handle);
48    }
49
50    for handle in handles {
51        handle.join().unwrap();
52    }
53
54    println!("   Final state: initialized = {}", initialized.load());
55
56    // Example 3: Producer-Consumer signaling
57    println!("\n3. Producer-Consumer Signaling:");
58    let ready = Arc::new(AtomicBool::new(false));
59    let data = Arc::new(AtomicBool::new(false));
60
61    let ready_clone = ready.clone();
62    let data_clone = data.clone();
63
64    // Producer thread
65    let producer = thread::spawn(move || {
66        println!("   Producer: preparing data...");
67        thread::sleep(Duration::from_millis(100));
68        data_clone.store(true);
69        ready_clone.store(true);
70        println!("   Producer: data ready!");
71    });
72
73    // Consumer thread
74    let consumer = thread::spawn(move || {
75        println!("   Consumer: waiting for data...");
76        while !ready.load() {
77            thread::yield_now();
78        }
79        println!("   Consumer: received data = {}", data.load());
80    });
81
82    producer.join().unwrap();
83    consumer.join().unwrap();
84
85    // Example 4: Toggle operations
86    println!("\n4. Toggle Operations:");
87    let flag = Arc::new(AtomicBool::new(false));
88    let mut handles = vec![];
89
90    for i in 0..10 {
91        let flag = flag.clone();
92        let handle = thread::spawn(move || {
93            for _ in 0..10 {
94                flag.fetch_not();
95            }
96            println!("   Thread {} completed 10 toggles", i);
97        });
98        handles.push(handle);
99    }
100
101    for handle in handles {
102        handle.join().unwrap();
103    }
104
105    println!("   Final state: {} (after 100 toggles)", flag.load());
106
107    println!("\n=== Example completed ===");
108}
Source

pub fn fetch_and(&self, value: bool) -> bool

Atomically performs logical AND, returning the old value.

§Memory Ordering

Uses AcqRel ordering. This ensures full synchronization with other threads for this read-modify-write operation, which is necessary because the operation depends on the current value.

§Parameters
  • value - The value to AND with.
§Returns

The old value before the operation.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(true);
assert_eq!(flag.fetch_and(false), true);
assert_eq!(flag.load(), false);
Source

pub fn fetch_or(&self, value: bool) -> bool

Atomically performs logical OR, returning the old value.

§Memory Ordering

Uses AcqRel ordering. This ensures full synchronization with other threads for this read-modify-write operation, which is necessary because the operation depends on the current value.

§Parameters
  • value - The value to OR with.
§Returns

The old value before the operation.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
assert_eq!(flag.fetch_or(true), false);
assert_eq!(flag.load(), true);
Source

pub fn fetch_xor(&self, value: bool) -> bool

Atomically performs logical XOR, returning the old value.

§Memory Ordering

Uses AcqRel ordering. This ensures full synchronization with other threads for this read-modify-write operation, which is necessary because the operation depends on the current value.

§Parameters
  • value - The value to XOR with.
§Returns

The old value before the operation.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
assert_eq!(flag.fetch_xor(true), false);
assert_eq!(flag.load(), true);
Source

pub fn set_if_false(&self, new: bool) -> Result<(), bool>

Conditionally sets the value if it is currently false.

Uses AcqRel ordering on success and Acquire ordering on failure.

§Parameters
  • new - The new value to set if current is false.
§Returns

Ok(()) if the value was false and has been set to new, Err(true) if the value was already true.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(false);
assert!(flag.set_if_false(true).is_ok());
assert_eq!(flag.load(), true);

// Second attempt fails
assert!(flag.set_if_false(true).is_err());
Examples found in repository?
examples/boolean_flag.rs (line 40)
18fn main() {
19    println!("=== Atomic Boolean Flag Example ===\n");
20
21    // Example 1: Simple flag
22    println!("1. Simple Flag:");
23    let flag = AtomicBool::new(false);
24    println!("   Initial value: {}", flag.load());
25
26    flag.store(true);
27    println!("   After set(true): {}", flag.load());
28
29    flag.fetch_not();
30    println!("   After negate: {}", flag.load());
31
32    // Example 2: One-time initialization
33    println!("\n2. One-time Initialization:");
34    let initialized = Arc::new(AtomicBool::new(false));
35    let mut handles = vec![];
36
37    for i in 0..5 {
38        let initialized = initialized.clone();
39        let handle = thread::spawn(move || {
40            if initialized.set_if_false(true).is_ok() {
41                println!("   Thread {} performed initialization", i);
42                thread::sleep(Duration::from_millis(100));
43            } else {
44                println!("   Thread {} skipped (already initialized)", i);
45            }
46        });
47        handles.push(handle);
48    }
49
50    for handle in handles {
51        handle.join().unwrap();
52    }
53
54    println!("   Final state: initialized = {}", initialized.load());
55
56    // Example 3: Producer-Consumer signaling
57    println!("\n3. Producer-Consumer Signaling:");
58    let ready = Arc::new(AtomicBool::new(false));
59    let data = Arc::new(AtomicBool::new(false));
60
61    let ready_clone = ready.clone();
62    let data_clone = data.clone();
63
64    // Producer thread
65    let producer = thread::spawn(move || {
66        println!("   Producer: preparing data...");
67        thread::sleep(Duration::from_millis(100));
68        data_clone.store(true);
69        ready_clone.store(true);
70        println!("   Producer: data ready!");
71    });
72
73    // Consumer thread
74    let consumer = thread::spawn(move || {
75        println!("   Consumer: waiting for data...");
76        while !ready.load() {
77            thread::yield_now();
78        }
79        println!("   Consumer: received data = {}", data.load());
80    });
81
82    producer.join().unwrap();
83    consumer.join().unwrap();
84
85    // Example 4: Toggle operations
86    println!("\n4. Toggle Operations:");
87    let flag = Arc::new(AtomicBool::new(false));
88    let mut handles = vec![];
89
90    for i in 0..10 {
91        let flag = flag.clone();
92        let handle = thread::spawn(move || {
93            for _ in 0..10 {
94                flag.fetch_not();
95            }
96            println!("   Thread {} completed 10 toggles", i);
97        });
98        handles.push(handle);
99    }
100
101    for handle in handles {
102        handle.join().unwrap();
103    }
104
105    println!("   Final state: {} (after 100 toggles)", flag.load());
106
107    println!("\n=== Example completed ===");
108}
Source

pub fn set_if_true(&self, new: bool) -> Result<(), bool>

Conditionally sets the value if it is currently true.

Uses AcqRel ordering on success and Acquire ordering on failure.

§Parameters
  • new - The new value to set if current is true.
§Returns

Ok(()) if the value was true and has been set to new, Err(false) if the value was already false.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;

let flag = AtomicBool::new(true);
assert!(flag.set_if_true(false).is_ok());
assert_eq!(flag.load(), false);

// Second attempt fails
assert!(flag.set_if_true(false).is_err());
Source

pub fn inner(&self) -> &StdAtomicBool

Gets a reference to the underlying standard library atomic type.

This allows direct access to the standard library’s atomic operations for advanced use cases that require fine-grained control over memory ordering.

§Memory Ordering

When using the returned reference, you have full control over memory ordering. Choose the appropriate ordering based on your specific synchronization requirements.

§Returns

A reference to the underlying std::sync::atomic::AtomicBool.

§Example
use prism3_rust_concurrent::atomic::AtomicBool;
use std::sync::atomic::Ordering;

let flag = AtomicBool::new(false);
flag.inner().store(true, Ordering::Relaxed);
assert_eq!(flag.inner().load(Ordering::Relaxed), true);

Trait Implementations§

Source§

impl Atomic for AtomicBool

Source§

type Value = bool

The value type stored in the atomic.
Source§

fn load(&self) -> bool

Loads the current value. Read more
Source§

fn store(&self, value: bool)

Stores a new value. Read more
Source§

fn swap(&self, value: bool) -> bool

Swaps the current value with a new value, returning the old value. Read more
Source§

fn compare_set(&self, current: bool, new: bool) -> Result<(), bool>

Compares and sets the value atomically. Read more
Source§

fn compare_set_weak(&self, current: bool, new: bool) -> Result<(), bool>

Weak version of compare-and-set. Read more
Source§

fn compare_exchange(&self, current: bool, new: bool) -> bool

Compares and exchanges the value atomically, returning the previous value. Read more
Source§

fn compare_exchange_weak(&self, current: bool, new: bool) -> bool

Weak version of compare-and-exchange. Read more
Source§

fn fetch_update<F>(&self, f: F) -> bool
where F: Fn(bool) -> bool,

Updates the value using a function, returning the old value. Read more
Source§

impl Debug for AtomicBool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AtomicBool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for AtomicBool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<bool> for AtomicBool

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl Send for AtomicBool

Source§

impl Sync for AtomicBool

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.