Process synchronization - An easy explanation


Process Synchronization is simply about running multiple processes that are accessing the same common resource (or resources) in a specific, controlled order so that everything goes smoothly and there’s no conflict.
Here, multiple processes (or even threads) could be sharing resources like a file, a database, or some part of the memory — and synchronization ensures that they don’t mess things up for each other.
A simple example:
Imagine we have a database and two programs - Program A and Program B.
Program A is responsible for adding/ updating (writing) a record to the database.
Program B is responsible for reading a record from the database.
Now, there are 5 records in the database. Program B wants to read record 5, while Program A wants to edit and update record 5. If both programs attempt to access the record simultaneously, it could lead to problems, such as Program B reading a half-updated record.
To avoid this, synchronization is essential. The solution here is to lock the resource while either program is using it. If Program B decides to read record 5, the database should be locked from Program A’s access. This ensures that Program B reads the complete, unaltered data. (However program B here would be reading old data which is later updated)
Similarly, when Program A is updating the record, the database should be locked for Program B’s access. Once Program A has finished updating this lock is released.
Note: Multiple programs that only want to read from the same database can do so simultaneously without locking each other out. This is because reading data doesn’t change anything, so one program’s reading doesn’t affect another’s.
Well that was all :) .
Source (my blog) : https://insanelogs.xyz/posts/process-synchronization-an-easy-explanation/
Subscribe to my newsletter
Read articles from Insane Logs directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Insane Logs
Insane Logs
Hi, I am Insane. Insanelogs - Log of insane Main website: https://www.insanelogs.xyz Blog website: https://blog.insanelogs.xyz My objective with InsaneLogs is to share knowledge and quick tutorials across different domains of computer science that I learn every day — in a simple and easy-to-understand manner. The goal is to help you get started with a topic quickly, and then dive deeper on your own. I believe it’s always better to have something working or functional first, before reading a ton of theory about it!