The following sequence of events will produce the output you see.
- thread 0 executes
y = 25;
- thread 0 executes
y = 10;
- thread 0 executes
printf("befor the barrier y: %d, tid:%d\n", y,tid);
- thread 1 executes
y = 25;
- thread 1 executes
printf("befor the barrier y: %d, tid:%d\n", y,tid);
- both threads exit barrier
- thread 0 executes
printf("after the barrier y: %d, tid:%d\n", y,tid);
- thread 1 executes
printf("after the barrier y: %d, tid:%d\n", y,tid);
This sequence of events is not at variance with the requirements of OpenMP.
The barrier ensures that all threads wait at the barrier until the last thread catches up at which point all threads may continue computing. The barrier does not affect the sequencing of events on different threads prior to their reaching it, nor indeed after they have left it. The barrier guarantees that all threads have executed all (their share of) the code prior to the barrier, but no more than that.