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.
readresults in an atomic read of the location designated byx. The statement has the following form:v = x;
writeresults in an atomic write of the location designated byx. The statement has the following form:v = expr;
updateresults in an atomic update of the location designated byxusing the designated operator or intrinsic. Only the read and write of the location designed byxare performed mutually atomically. The statement has the following form:x++; x--; ++x; --x; x binop= expr; x = x binop expr; x = expr binop x;
captureis an atomic capture update. That is, an atomic update to the location designed byxusing the designated operator or intrinsic while also capturing the original or final value of the location designed byxwith respect to the atomic update. The original or final value of the location designated byxis written in the location designated byv. Only the read and write of the location designed byxare 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.