as 'volatile'. Note however that the C/C++ "volatile" attribute only guarantees that the compiler generates code with the proper ordering; it does not include the necessary memory barriers to guarantee in-order execution of that code. C++11 atomic variables can be used to guarantee the appropriate ordering requirements — by default, operations on atomic variables are sequentially consistent so if the wants_to_enter and turn variables are atomic a naive implementation will "just work". Alternatively, ordering can be guaranteed by the explicit use of separate fences, with the load and store operations using a relaxed ordering. See also Eisenberg & McGuire algorithm Peterson's algorithm Lamport's bakery algorithm Szymański's algorithm Semaphores References Concurrency control algorithms Edsger W. Dijkstra Articles with example pseudocode