Skip to content

data races in openmp on shared boolean flags #7371

@ben-schwen

Description

@ben-schwen

The openmp documentation states our common used idiom e.g. setting shared boolean flag is UB in openmp.

Two memory operations are considered unordered if the order in which they must complete, as seen by their affected threads, is not specified by the memory consistency guarantees listed in Section 1.4.6. If multiple threads write to the same memory unit (defined consistently with the above access considerations) then a data race occurs if the writes are unordered. Similarly, if at least one thread reads from a memory unit and at least one thread writes to that same memory unit then a data race occurs if the read and write are unordered. If a data race occurs then the result of the program is unspecified.

#pragma omp parallel for
for (int i = 0; i < n; i++) {
    shared_flag = true;   // UB: concurrent unsynchronized writes
}

Originally posted by @ben-schwen in #7361 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions