Critical Section

Critical section is any piece of code that has the possibility of being executed concurrently by more than one thread of the application and exposes any shared data or resources used by the application for access.

Race Condition

Race conditions happen when threads run through critical sections without thread synchronization. The threads "race" through the critical section to write or read shared resources and depending on the order in which threads finish the "race", the program output changes.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0c68c8ec-e3cf-4e89-9e1a-d772354ebefb/Untitled.png