icp/oer/courses/c-openmp/sections/02-advanced/04-atomic/content.md

568 B

Another synchronization method are atomics.

Knowledge

Atomics ensure that the marked variables are updated in one step, without any interuptions. That way no other thread can corrupt the data. They are not as versatile as critical sections, but if you can use them, they are faster. If you are in a situation, where you can a reduction, you should do so, because even though atomics are fast, the less synchronizations of the reductions will still save more time.

Task

We use the same program as before. Use the atomic directive to solve the race condition.