Atomic constructΒΆ
Warning
The following information applies to clang. Mercurium
does support atomic
, but without clauses.
The atomic
construct ensures that a specific storage location is
accessed atomically, rather than exposing it to the possibility of
multiple, simultaneous reading and writing threads that may result in indeterminate values:
#pragma oss atomic
statement
The construct allows the clauses read
, write
, and update
to define
the semantics for which a directive enforces atomicity. If no clause is present,
the behavior is as if the update
clause is specified.
read
results in an atomic read of the location designated byx
. The statement has the following form:v = x;
write
results in an atomic write of the location designated byx
. The statement has the following form:v = expr;
update
results in an atomic update of the location designated byx
using the designated operator or intrinsic. Only the read and write of the location designed byx
are performed mutually atomically. The statement has the following form:x++; x--; ++x; --x; x binop= expr; x = x binop expr; x = expr binop x;
capture
is an atomic capture update. That is, an atomic update to the location designed byx
using the designated operator or intrinsic while also capturing the original or final value of the location designed byx
with respect to the atomic update. The original or final value of the location designated byx
is written in the location designated byv
. Only the read and write of the location designed byx
are performed mutually atomically. The statement has the following form:v = expr-stmt { v = x; expr-stmt } { expr-stmt v = x; }
where expr-stmt is either an atomic write or update statement.
The atomic
construct also allows memory order clauses:
relaxed
, acquire
, release
, acq_rel
, seq_cst
.
If no memory order clause is specified the default memory ordering is
relaxed
.