<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Miss E .D .C &#187; SIMULATION OF MUTUAL EXCLUSION WITH THE USE OF SEMAPHOR</title>
	<atom:link href="http://blog.ethelcofie.com/tag/simulation-of-mutual-exclusion-with-the-use-of-semaphor/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ethelcofie.com</link>
	<description>Thoughts on Software development,IT Business Consultancy,New Technologies and other random stuff i have done</description>
	<lastBuildDate>Mon, 23 May 2011 14:29:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Program for simulation of mutual exclusion with the use of semaphores</title>
		<link>http://blog.ethelcofie.com/2008/09/15/program-for-simulation-of-mutual-exclusion-with-the-use-of-semaphores/</link>
		<comments>http://blog.ethelcofie.com/2008/09/15/program-for-simulation-of-mutual-exclusion-with-the-use-of-semaphores/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 13:33:54 +0000</pubDate>
		<dc:creator>ethelcofie</dc:creator>
				<category><![CDATA[Development Articles]]></category>
		<category><![CDATA[Research Articles]]></category>
		<category><![CDATA[Alogirithm]]></category>
		<category><![CDATA[SIMULATION OF MUTUAL EXCLUSION WITH THE USE OF SEMAPHOR]]></category>

		<guid isPermaLink="false">http://etheldcofie.wordpress.com/?p=51</guid>
		<description><![CDATA[This java program simulates the use mutual exclusion using semaphores. The program involves four processes named process 1,2,3,4 who are competing for critical sections A,B,C,D,E,F,G. with a semaphore A for critical section A,sem Z for B,semC for B,sem D for section E, ,sem F for section F and lastly sem G for section G .]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><strong>Program for simulation of mutual exclusion with the use of semaphores </strong></p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><strong>PROBLEM DESCRIPTION</strong></p>
<p class="MsoNormal">In operating systems the problem of mutual exclusion is very often encountered because of multiple processes that access, modify certain shared resources such as data structures .The operating system need to ensure that these shared data structures are not accessed and modified<span> </span>by multiple processes at the same time causing incorrect results for the processes involved. One of the solutions to the problem of mutual exclusion is to use semaphores which as defined by <a href="http://encyclopedia.thefreedictionary.com/">http://encyclopedia.thefreedictionary.com</a> as a <strong>protected</strong> variable (or abstract data type) and constitutes the classic method for restricting access to shared resources (e.g. storage) in a multiprogramming environment. <span> </span></p>
<p class="MsoNormal">Semaphores have two basic functions, P():checks if critical section is filled then blocks or allows process as appropriate() function: checks when a process leaves critical section and removes it from semaphore queue.</p>
<p class="MsoNormal">The semaphores are used to implement these rules: to at most one process uses the shared data structure at a time (critical section) and all processes get their turn with the shared resource</p>
<p class="MsoNormal">
<p class="MsoNormal"><strong>PROGRAM DESCRIPTION</strong></p>
<p class="MsoNormal">This java program simulates the use mutual exclusion using semaphores. The program involves four processes named process 1,2,3,4 who are competing for critical sections A,B,C,D,E,F,G. with a semaphore A for critical section A,sem Z for B,semC for B,sem D for section E, ,sem F for section F and lastly sem G for section G .</p>
<p class="MsoNormal">The simulation program implements mutual exclusion by implementing these three rules:</p>
<p class="MsoNormal">1. At most one process may execute in the critical section a time i.e. all processes that request a critical section that is occupied are denied request and are to wait.</p>
<p class="MsoNormal">2. Request to enter and exit a critical section is eventually succeed: All processes that have made a request for a critical section may be denied a request initially but after a wait will get into the critical section when it is available.</p>
<p class="MsoNormal">3. Critical section request are prioritized on First come first served basis</p>
<p class="MsoNormal">
<p class="MsoNormal"><strong>HOW PROGRAM WORKS </strong></p>
<p class="MsoNormal">The program simulates a random request by any number of the processes for any of critical sections and implements the management of these process request using mutual exclusion rules stated above.</p>
<p class="MsoNormal">The program works by creating four processes, then creating 7 semaphores along corresponding to the 7 critical sections. The implements a P function whose primary task is to check when a process makes critical section request using the counter variable whether or not the critical section is occupied if it is it blocks the process until critical section is vacant else removing process from process queue and adding it to the semaphore queue</p>
<p class="MsoNormal">The program also implements the V function whose primary duty is to check for a process leaving a critical section decrease counter value flagging the critical section as vacant .This is implemented after a process sends a message of leaving the process</p>
<p class="MsoNormal"><strong> </strong></p>
<p class="MsoNormal"><strong>ALGORITHM</strong></p>
<p class="MsoNormal"><span> </span>Create Processes</p>
<p class="MsoNormal"><span> </span>Create all 7 critical sections</p>
<p class="MsoNormal"><span> </span>Create corresponding semaphores for each critical section</p>
<p class="MsoNormal"><span> </span>If for a process request for a critical section</p>
<p class="MsoNormal">Then</p>
<p class="MsoNormal"><span> </span>Check if semaphore counter &gt;0</p>
<p class="MsoNormal"><span> </span>Refuse permission to enter section for process and request process to hold till critical section if available</p>
<p class="MsoNormal"><span> </span>Add process to semaphore queue</p>
<p class="MsoNormal"><span> </span><span> </span>If semaphore counter =0</p>
<p class="MsoNormal"><span> </span>Then</p>
<p class="MsoNormal"><span> </span>Grant permission to enter the critical section</p>
<p class="MsoNormal"><span> </span>Remove process from semaphore queue</p>
<p class="MsoNormal">
<p class="MsoNormal"><span> </span>If process sends an acknowledgement to leave the critical section</p>
<p class="MsoNormal"><span> </span>Then</p>
<p class="MsoNormal"><span> </span>Decrease semaphore counter</p>
<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal"><strong>DRAWING OF A SCENARIO OF THE MUTUAL EXCLUSION SIMULATION PROGRAM</strong></p>
<p class="MsoNormal"><strong> </strong></p>
<div id="attachment_53" class="wp-caption alignnone" style="width: 586px"><a href="http://blog.ethelcofie.com/wp-content/uploads/2008/09/mutex2.gif"><img class="size-full wp-image-53" title="mutex2" src="http://blog.ethelcofie.com/wp-content/uploads/2008/09/mutex2.gif" alt="DRAWING OF A SCENARIO OF THE MUTUAL EXCLUSION" width="576" height="193" /></a><p class="wp-caption-text">DRAWING OF A SCENARIO OF THE MUTUAL EXCLUSION</p></div>
<p class="MsoNormal"><strong> </strong></p>
<p class="MsoNormal"><strong> </strong></p>
<p class="MsoNormal"><!--[if gte vml 1]&gt;   &lt;![endif]--><!--[if !vml]--></p>
<p><strong>SCREEN SHOT OF MUTUAL EXCLUSION INVOLVING FOUR PROCESSES AND 7 CRITICAL SECTIONS AND THEIR METAPHORS</strong></p>
<p class="MsoNormal"><a href="http://blog.ethelcofie.com/wp-content/uploads/2008/09/mutex.gif"><img class="alignnone size-full wp-image-52" title="mutex" src="http://blog.ethelcofie.com/wp-content/uploads/2008/09/mutex.gif" alt="" width="577" height="485" /></a></p>
<p class="MsoNormal"><!--[if gte vml 1]&gt;  &lt;![endif]--><!--[if !vml]--><!--[endif]--></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ethelcofie.com/2008/09/15/program-for-simulation-of-mutual-exclusion-with-the-use-of-semaphores/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

