W3cubDocs

/Crystal

struct Atomic::Flag

Overview

An atomic flag, that can be set or not.

Concurrency safe. If many fibers try to set the atomic in parallel, only one will succeed.

Example:

flag = Atomic::Flag.new
flag.test_and_set # => true
flag.test_and_set # => false
flag.clear
flag.test_and_set # => true

Defined in:

atomic.cr

Constructors

Instance Method Summary

Constructor Detail

def self.newSource

Instance Method Detail

def clear : NilSource

Atomically clears the flag.

def test_and_set : BoolSource

Atomically tries to set the flag. Only succeeds and returns true if the flag wasn't previously set; returns false otherwise.

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Atomic/Flag.html