OpenMP® Forum

Discussion on the OpenMP specification run by the OpenMP ARB. OpenMP and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board in the United States and other countries. All rights reserved.

There is no restriction in the OpenMP V3.0 specification that prohibits this. That said, an atomic can be implemented with a critical construct and a critical construct cannot be nested within a critical region with the same name. That would mean that an implementation would have to make sure that if it used a critical construct to implement atomic, that it used a unique name.

But the specs 3.0 says that (page 104 line 30) nesting critical regions with different names is not sufficient to prevent deadlock.If it is possible to substitute an atomic by a critical construct I would have expected that nesting an atomic inside a criticalnot to be allowed like a critical/critical construct. So I am a bit confused.

You have it a little mixed up. A critical construct may be nested within a critical region as long as the names of the critical constructs are different. An atomic may be nested within a critical, because if you look at Section 2.8.5 atomic Construct, you will see that "atomic regions do not enforce exclusive access with respect to any critical or ordered regions that access the same storage location x". So you have to use an atomic if you are using an atomic elsewhere to update a storage location that both atomics are accessing.

The statement about data races is true, if an atomic happened to contain a critical region (or atomic) within the expression. Then it is possible that you could create a deadlock condition. However, all the spec is saying, is not allowing this to happen is not sufficient to prevent deadlocks. In the V3.1 specification atomic and critical are no longer allowed to be closely nested inside an atomic region.