answersLogoWhite

0

Explain binary semaphore and its uses?

Updated: 10/3/2023
User Avatar

Vishal

Lvl 1
12y ago

Best Answer

A binary semaphore is a semaphore with an integer

value that can range only between 0 and 1. A binary semaphore can be simpler

to implement than a counting semaphore, depending on the underlying

hardware architecture.To implement it in terms of binary

semaphores we need the following data structures:

binary-semaphore S1, S2;

i n t C;

Initially S1 = 1, S2 = 0, and the value of integer C is set to the initial value

of the counting semaphore S.The wait operation on the counting semaphore S can be implemented as

follows:

wait (S1) ;

c--;

i f (C < 0) {

signal(S1) ;

wait (S2) ;

}

signal(S1)

The signal operation on the counting semaphore S can be implemented

as follows:

w a i t (S1) ;

C++ ;

i f (C <= 0)

signal (S2) ;

e l s e

signal (S1) ;

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

A binary semaphore is one, which takes only 0 and 1 as values. They are used to implement mutual exclusion and synchronize concurrent processes.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Explain binary semaphore and its uses?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is difference between counting and binary semaphore in os?

Binary semaphore is a semaphore with the integer value ranges over 0 and 1 whereas the counting semaphore's integer value ranges over unrestricted domain. Binary semaphores are easier to implement comparing with the counting semaphore. Binary semaphore allows only one thread to access the resource at a time. But counting semaphore allows N accesses at a time. The 2 operations that are defined for binary semaphores are take and release. The 2 operations that are defined for counting semaphores are wait and signal


What is the name of the comminication system that uses flags?

semaphore


Explain semaphore concept in multiprogramming?

A semaphore is a service very often offered by real-time operating systems to allow programmers to perform one of two major functions: synchronize 2 tasks or control sharing of resources between 2 or more tasks. There are different kinds of semaphores, but one of the most common is called a binary semaphore. In this kind of semaphore, only 1 task at a time may "have" the semaphore. The simplest way to think of the binary semaphore might be to consider the semaphore like a baton and there is only one baton. Say if you want to allow only 1 person to speak at a time (consider people to be tasks), then you make a rule that only the person holding the baton may speak. A person wanting to speak will go and pick up the baton. If nobody else has it, he may speak. If someone else has it, he must wait until the baton is put down by whoever has it. This is the "sharing resources" way a semaphore is used. The task synchronization usage, similarly can be thought of using this baton. Just as in a relay race where one person cannot start until another passes the baton, a binary semaphore can be used to synchronize two tasks by giving one task the semaphore, having the second one wait for the semaphore, and then having the first give it to the second. The two tasks will be synchronized at the point the semaphore is passed from the first to the second just as a baton is passed from one runner to the next in a relay race. You can have semaphores other than binary semaphores, which are called counting semaphores. Counting semaphores are just binary semaphores generalized to more than the 2 values of 0 and 1, to some value n.


Is Naval semaphore which uses flags to communicate a type of telegraph?

True


Explain why Boolean logic is so important for computers?

Because computers uses binary as its language. And programs are representation of logic.


Do binary codes uses 1 and 2?

binary codes uses 0 and 1


How do you use semaphore in an easy sentence?

The meaning of semaphore is to give information by using visual signals so when using it in a sentence, it must be used to replace the explanation of the signals. An example of a sentence is the airport grounds crew uses semaphores to guide the pilot of the plane.


What is the meaning of binary form?

Our system uses 10 numbers: 0123456789. Binary only uses 0 and 1. Our 1 is binary 1, but because there are no more numbers to use, our 2 is binary 10, our 3 is binary 11, our 4 is binary 100, and so on.


What numbers are used in binary?

Binary uses only the digits 0 and 1.


A bus based multiprocessor uses Snoopy cache to achieve coherent memory. will semaphore works on this process?

yes


What are the types of semaphores?

Three types of semaphores: 1.General/Counting semaphores: (can take any non-negative value) These are used when you might have multiple devices (like 3 printers or multiple memory buffers). 2.Binary semaphores: (can either be 0 or 1) These are used to gain exclusive access to a single resource (like the serial port, a non-reentrant library routine, or a hard disk drive). A counting semaphore that has a maximum value of 1 is equivalent to a binary semaphore (because the semaphore's value can only be 0 or 1). 3.Mutex semaphores: These are optimized for use in controlling mutually exclusive access to a resource. There are several implementations of this type of semaphore.


What is the difference between MUTEX and Semaphore?

From wikipedia:"A mutex is a binary semaphore, usually including extra features like ownership or priority inversion protection. The differences between mutexes and semaphores are operating system dependent. Mutexes are meant to be used for mutual exclusion only and binary semaphores are meant to be used for event notification and mutual exclusion."They also have a good example as to the use of a semaphore:"A thread named A needs information from two databases before it can proceed. Access to these databases is controlled by two separate threads B, C. These two threads have a message-processing loop; anybody needing to use one of the databases posts a message into the corresponding thread's message queue. Thread A initializes a semaphore S with init(S,-1). A then posts a data request, including a pointer to the semaphore S, to both B and C. Then A calls P(S), which blocks. The other two threads meanwhile take their time obtaining the information; when each thread finishes obtaining the information, it calls V(S) on the passed semaphore. Only after both threads have completed will the semaphore's value be positive and A be able to continue. A semaphore used in this way is called a 'counting semaphore.'"Basically think of a semaphore as a lock that allows multiple threads to wait in line for the resource to be free. Usually they will block and the semaphore will wake them up when it is their turn.