how do computers solve/prevent race conditions in process synchronization

99 viewsOtherTechnology

I understand that a race condition occurs when two programs (process) try to access to a a common variable (for example, P1 tries to add 1 to the common value 10, but P2 tries to substract 1 to 10), which could lead to incorrect data, deadlockss etc but how can this be avoided and/or solved if it happens?

In: Technology

Anonymous 0 Comments

It depends on the particular thing being done, but one common method is to create something as a “lock” (such as a separate file or variable) which is only able to be set by one process and it remains until that process is done. Another method, such as when you have multiple redundant services, is to elect one of them as the master so that it gets to make the call.