I think the type of "n" in your Thread1 should be unsigned or add some codes to limit its increasement (n++) in case it becomes negative,
and the shared memory should be synchronized. I am not very sure if it is no problem in practice of this specific implementation to access the shared memory without synchronization.
This post has been archived. It cannot be replied.