I was trying to learn something about parallel programming, so I tried to implement Peterson\'s algorithm for an easy example where one shared counter is incremented by 2 th
You have several problems here:
volatile
, at least.++
operator is not atomic.There would be several ways around this, in particular the new C standard C11 offers atomic primitives. But if this is really meant for you as a start to learn parallel programming, I'd strongly suggest that you first look into mutexes, condition variables etc, to learn how POSIX is intended to work.