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 by x. The statement has the following form:

    v = x;
    
  • write results in an atomic write of the location designated by x. The statement has the following form:

    v = expr;
    
  • update results in an atomic update of the location designated by x using the designated operator or intrinsic. Only the read and write of the location designed by x 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 by x using the designated operator or intrinsic while also capturing the original or final value of the location designed by x with respect to the atomic update. The original or final value of the location designated by x is written in the location designated by v. Only the read and write of the location designed by x 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.