TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

OS Binary Semaphore or Mutex

OS Binary Semaphore or Mutex with Definition and functions, OS Tutorial, Types of OS, Process Management Introduction, Attributes of a Process, Process Schedulers, CPU Scheduling, SJF Scheduling, FCFS with overhead, FCFS Scheduling etc.

<< Back to OS

Binary Semaphore or Mutex

In counting semaphore, Mutual exclusion was not provided because we has the set of processes which required to execute in the critical section simultaneously.

However, Binary Semaphore strictly provides mutual exclusion. Here, instead of having more than 1 slots available in the critical section, we can only have at most 1 process in the critical section. The semaphore can have only two values, 0 or 1.

Let's see the programming implementation of Binary Semaphore.


StructBsemaphore
{
	enum Value(0,1); //value is enumerated data type which can only have two values 0 or 1.
	Queue type L;
}
/* L contains all PCBs corresponding to process 
Blocked while processing down operation unsuccessfully. 
*/ 
Down (Bsemaphore S) 
{
	if (s.value == 1) // if a slot is available in the 
	//critical section then let the process enter in the queue. 
	{
		S.value = 0; // initialize the value to 0 so that no other process can read it as 1. 
	}
	else
	{
		put the process (PCB) in S.L; //if no slot is available 
		//then let the process wait in the blocked queue. 
		sleep(); 
	}
}
Up (Bsemaphore S) 
{
	if (S.L is empty) //an empty blocked processes list implies that no process 
	//has ever tried to get enter in the critical section. 
	{
		S.Value =1; 
	}
	else
	{
		Select a process from S.L; 
		Wakeup(); // if it is not empty then wake the first process of the blocked queue. 
	} 
}






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf