Your program is not conforming, and yields undefined behavior. In particular if you check the latest standard you can find in section 2.7.1 the following restriction for the loop construct:
- The loop iteration variable may not appear in a threadprivate directive
In your case what is likely to happen is a name clash between two variables named test
: one should be a private int
variable created for the loop iteration while the other is the global variable declared as threadprivate. But again, being undefined behavior, anything may happen.