Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What is a semaphore mechanism ?

Status
Not open for further replies.

cosmos4k

Newbie level 6
Joined
Apr 14, 2005
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,361
semaphore explain

What is a semaphore mechanism ?

i want to know the detail
plz help
 

Re: explain

When a datastructure is shared across many processes, accidental change of the data by some other process while the other process is using it might corrupt the data. Semaphore is just a locking mechanism, it uses locked code ot decrement a counter & see if the counter is less than or equal to 0. If it is, the semaphore is locked by some other process, else your process got the semaphore. Use the datastructure associated with it & release the semaphore by incrementing the counter. The scheduler in OS will take care of issuing the semaphore to the next waiting process, once you released it. For further reading refer to some OS books, however small the texts are, they definitely give you some good information on them.

Srinu
 

explain

Generally semaphore can schedule multi-tasks processing. It mainly be used in two ways: synchronization and mutex.
 

Re: explain semaphore

then whats the difference between semaphore and flag . all things using semaphore can b done using flag.

Is flag is implemented in RTOS or OS as semaphore with some clearcut rules ( as given by its inventer ) of using it and features OS provides.?
shreshtha
 

Re: explain

A semaphore is a protected variable (or abstract data type) and constitutes the classic method for restricting access to shared resources (e.g. storage) in a multi-processing environment. They were invented by Dijkstra and first used in the T.H.E. operating system.

Semaphores can only be accessed using the following operations:


P(Semaphore s)
{
while (s == 0) ; /* wait until s>0 */
s = s-1;
}

V(Semaphore s)
{
s = s+1;
}

Init(Semaphore s, Integer v)
{
s = v;
}
P and V stand for Dutch "Proberen", to test, and "Verhogen", to increment. The value of a semaphore is the number of units of the resource which are free. (If there is only one resource, a "binary semaphore" with values 0 or 1 is used.) The P operation busy-waits (or maybe sleeps) until a resource is available whereupon it immediately claims one. V is the inverse; it simply makes a resource available again after the process has finished using it. Init is only used to initialise the semaphore before any requests are made. The P and V operations must be indivisible, which means that each of the operations may not be executed multiple times concurrently. A process wishing to execute an operation that is already being executed by another process must wait for it to complete first.

The V operation is sometimes known as "up", and the P operation as "down".

To avoid busy-waiting, a semaphore may have an associated queue of processes (usually a FIFO). If a process performs a P operation on a semaphore which has the value zero, the process is added to the semaphore's queue. When another process increments the semaphore by performing a V operation, and there are processes on the queue, one of them is removed from the queue and resumes execution.



hope it helped

helios
h**p://hi.raj.tripod.com
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top