#explanations on atomic order

1 messages · Page 1 of 1 (latest)

graceful kestrel
#

What atomic orders should i use for what operations, or rather, which orders are commonly used for which operations.

one operation im trying to do is returning an element from an array, it's a copy by value so no modifications.

i've been using seq_cst but i think that's the slowest one so far and probably overkill?

Sorry if i'm a bit vague, very new to atomics

#

this is the function i have so far.

pub fn getFoo(self: *const FooManager, index: usize) Foo {
    return @atomicLoad(Foo, &self.arr_foo[index], .seq_cst);
}
#

sadly std.builtin.AtomicOrder has no documentation

blazing forge
#

The ordering only affects other memory operations around the atomic. Should probably avoid atomics if you can help it. Whats arr_foo used for?

graceful kestrel
#

I wanted to try atomics because im hoping it might be a bit faster than mutex locks.

#

^ would also mean less potential for dead locks

blazing forge
#

is the value of Foo being used to then read other memory?

#

e.g. write memory; STORE(&arr_foo[10], v) -> if LOAD(&arr_foo[10]) == v: read_memory

graceful kestrel
#

yes, i check if the old foo contains certain data
if its not, i set the old foo to the new foo.

#

goes something like this in code

const old_foo = LOAD(&arr_foo[10]);

if (old_foo is something specific)
  return;

arr_foo[10] = new_foo;
polar magnet
raw karma