{"id":6267,"date":"2025-09-15T11:47:34","date_gmt":"2025-09-15T06:17:34","guid":{"rendered":"https:\/\/study.madeeasy.in\/?p=6267"},"modified":"2025-09-15T11:47:34","modified_gmt":"2025-09-15T06:17:34","slug":"synchronization","status":"publish","type":"post","link":"https:\/\/www.madeeasy.in\/study\/cs-it\/operating-system\/synchronization","title":{"rendered":"Synchronization"},"content":{"rendered":"<p style=\"text-align: justify;\">Threads (or processes) are concurrent if they exist at the same time. They are asynchronous if they need to synchronize with each other occasionally. They are independent if they have no dependence on each other: it does not affect a thread whether another thread exists or not. Threads are synchronous if they synchronize<br \/>\nfrequently so that their relative order of execution is guaranteed.<\/p>\n<p style=\"text-align: justify;\">Problems Arising When Not Having Synchronization<\/p>\n<p style=\"text-align: justify;\">(i) Inconsistency<br \/>\n(ii) Loss of data<br \/>\n(iii) Deadlock<\/p>\n<p style=\"text-align: justify;\">Let us understand each one of then with the help of examples.<\/p>\n<p style=\"text-align: justify;\"><strong>Producer-Consumer Problem:<\/strong> Here the producerprocess generates an item into the buffer, and the consumer process consumes the item out of the buffer.<\/p>\n<p style=\"text-align: justify;\">Buffer of size N (shared resource) with in and out variables to indicate the next position for putting data into the buffer and fetching data from the buffer, respectively. Count maintains a count of the number of items present in buffer (shared resource).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-6268 size-full\" src=\"https:\/\/study.madeeasy.in\/wp-content\/uploads\/2025\/09\/synchronization.jpg\" alt=\"Synchronization\" width=\"891\" height=\"426\" srcset=\"https:\/\/www.madeeasy.in\/study\/wp-content\/uploads\/2025\/09\/synchronization.jpg 891w, https:\/\/www.madeeasy.in\/study\/wp-content\/uploads\/2025\/09\/synchronization-300x143.jpg 300w, https:\/\/www.madeeasy.in\/study\/wp-content\/uploads\/2025\/09\/synchronization-768x367.jpg 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><\/p>\n<p>Now produce execute III statement of count<br \/>\nIII. count = 4<br \/>\nHere the buffer contains only 3 items, but the count value is 4.<br \/>\nIt is because the producer and consumer are not properly synchronized while sharing the common variable count. Hence leading to inconsistency.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Threads (or processes) are concurrent if they exist at the same time. They are asynchronous if they need to synchronize<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94,3],"tags":[1851,1850,1849],"class_list":["post-6267","post","type-post","status-publish","format-standard","hentry","category-operating-system","category-cs-it","tag-deadlock","tag-inconsistency","tag-synchronization"],"_links":{"self":[{"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/posts\/6267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/comments?post=6267"}],"version-history":[{"count":0,"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/posts\/6267\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/media?parent=6267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/categories?post=6267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.madeeasy.in\/study\/wp-json\/wp\/v2\/tags?post=6267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}