
[Greek sēma, sign + -PHORE.]
semaphoric sem'a·phor'ic adj.For more information on semaphore, visit Britannica.com.
(1) A hardware or software flag used to indicate the status of some activity.
(2) A shared space for interprocess communications (IPC) controlled by "wake up" and "sleep" commands. The source process fills a queue and goes to sleep until the destination process uses the data and tells the source process to wake up.
Download Computer Desktop Encyclopedia to your PC, iPhone or Android.
The semaphore is a visual communications system, which usually uses flags or lights to spell out letters. In 1792, Claude Chappe, a French engineer, devised an optical semaphore system that could carry a message 143 miles (230 km) from Lille to Paris in two minutes. It was designed with a set of arms that pivoted on a post. The positions of the arms determined the meaning of the message. The arms were attached to towers that were spaced 5-10 miles (8-16 km) apart. Messages were read by a telescope at each tower. Other nations adopted Chappe's invention which was not superseded by the electric telegraph until about 1850.
Hutton Gregory, a telegraph engineer on the British railways, developed a modified version of Chappe's semaphore for railroads in the early 1840s. His system employed moving metal arms or rows of lights, mounted on towers to signal trains. This system is still in effect today.
Semaphore also remains in use for maritime communications. The flags are usually square, red and yellow, divided diagonally with the red portion in the upper hoist. The flags are held, arms extended, in various positions representing each of the letters of the alphabet or numbers. The arms are kept straight when changing from one position to another. This system is used for short distance signalling. Use of semaphore flags was limited to within range of telescopes in earlier days and binoculars today. The colours were chosen for long-distance visibility. Ships also use flashing lights between vessels—the Aldis lamp—as another means of semaphore signalling.
— Danny M. Johnson
n. 1. a system of sending messages by holding the arms or two flags or poles in certain positions according to an alphabetic code.
2. an apparatus for signaling in this way, consisting of an upright with movable parts.
3. a signal sent by semaphore.
v.send (a message) by semaphore or by signals resembling semaphore: Josh stands facing the rear and semaphoring the driver's intentions.
semaphoric adj. semaphorically adv.
See the Introduction, Abbreviations and Pronunciation for further details.
LearnThatWord.com is a free vocabulary and spelling program where you only pay for results!

In computer science, a semaphore is a variable or abstract data type that provides a simple but useful abstraction for controlling access by multiple processes to a common resource in a parallel programming environment.
A useful way to think of a semaphore is as a record of how many units of a particular resource are available, coupled with operations to safely (i.e., without race conditions) adjust that record as units are required or become free, and if necessary wait until a unit of the resource becomes available. Semaphores are a useful tool in the prevention of race conditions; however, their use is by no means a guarantee that a program is free from these problems. Semaphores which allow an arbitrary resource count are called counting semaphores, while semaphores which are restricted to the values 0 and 1 (or locked/unlocked, unavailable/available) are called binary semaphores (same functionality that mutexes have).
The semaphore concept was invented by Dutch computer scientist Edsger Dijkstra,[1] and the concept has found widespread use in a variety of operating systems.
|
Contents
|
Suppose a library has 10 identical study rooms, intended to be used by one student at a time. To prevent disputes, students must request a room from the front counter if they wish to make use of a study room. When a student has finished using a room, the student must return to the counter and indicate that one room has become free. If no rooms are free, students wait at the counter until someone relinquishes a room.
The librarian at the front desk does not keep track of which room is occupied, only the number of free rooms available. When a student requests a room, the librarian decreases this number. When a student releases a room, the librarian increases this number. Once access to a room is granted, the room can be used for as long as desired, and so it is not possible to book rooms ahead of time.
In this scenario the front desk represents a semaphore, the rooms are the resources, and the students represent processes. The value of the semaphore in this scenario is initially 10. When a student requests a room he or she is granted access and the value of the semaphore is changed to 9. After the next student comes, it drops to 8, then 7 and so on. If someone requests a room and the resulting value of the semaphore is negative,[2] they are forced to wait. When multiple people are waiting, they will either wait in a queue, or use Round-robin scheduling and race back to the counter when someone releases a room (depending on the nature of the semaphore).
When used for a pool of resources, a semaphore does not keep track of which of the resources are free, only how many there are. Some other mechanism (possibly involving more semaphores) may be required to select a particular free resource.
Processes are trusted to follow the protocol. Fairness and safety are likely to be compromised (which practically means a program may behave slowly, act erratically, hang or crash) if even a single process acts incorrectly. This includes:
Even if all processes follow these rules, multi-resource deadlock may still occur when there are different resources managed by different semaphores and when processes need to use more than one resource at a time, as illustrated by the dining philosophers problem.
One important property of these semaphore variables is that their value cannot be changed except by using the wait() and signal() functions.
Counting semaphores are equipped with two operations, historically denoted as V (also known as signal()) and P (or wait())(see below). Operation V increments the semaphore S, and operation P decrements it. The semantics of these operations are shown below. Square brackets are used to indicate atomic operations, i.e., operations which appear indivisible from the perspective of other processes.
The value of the semaphore S is the number of units of the resource that are currently available. The P operation wastes time or sleeps until a resource protected by the semaphore becomes available, at which time the resource is immediately claimed. The V operation is the inverse: it makes a resource available again after the process has finished using it.
A simple way to understand wait() and signal() operations is:
wait(): Decrements the value of semaphore variable by 1. If the value becomes negative, the process executing wait() is blocked, i.e., added to the semaphore's queue.signal(): Increments the value of semaphore variable by 1. After the increment, if the value was negative (meaning there are processes waiting for a resource), it transfers a blocked process from the semaphore's waiting queue to the ready queue.Many operating systems provide efficient semaphore primitives that unblock a waiting process when the semaphore is incremented. This means that processes do not waste time checking the semaphore value unnecessarily.
The counting semaphore concept can be extended with the ability to claim or return more than one "unit" from the semaphore, a technique implemented in UNIX. The modified V and P operations are as follows:
function V(semaphore S, integer I):
[S ← S + I]
function P(semaphore S, integer I):
repeat:
[if S >= I:
S ← S - I
break]
To avoid starvation, a semaphore has an associated queue of processes (usually a first-in, first out). If a process performs a P operation on a semaphore that 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. When processes have different priorities the queue may be ordered by priority, so that the highest priority process is taken from the queue first.
If the implementation does not ensure atomicity of the increment, decrement and comparison operations, then there is a risk of increments or decrements being forgotten, or of the semaphore value becoming negative. Atomicity may be achieved by using a machine instruction that is able to read, modify and write the semaphore in a single operation. In the absence of such a hardware instruction, an atomic operation may be synthesized through the use of a software mutual exclusion algorithm. On uniprocessor systems, atomic operations can be ensured by temporarily suspending preemption or disabling hardware interrupts. This approach does not work on multiprocessor systems where it is possible for two programs sharing a semaphore to run on different processors at the same time. To solve this problem in a multiprocessor system a locking variable can be used to control access to the semaphore. The locking variable is manipulated using a test-and-set-lock (TSL) command.
In the Producer-consumer problem, one process (the producer) generates data items and another process (the consumer) receives and uses them. They communicate using a queue of maximum size N and are subject to the following conditions:
The semaphore solution to the Producer-consumer problem tracks the state of the queue with two semaphores: emptyCount, the number of empty places in the queue, and fullCount, the number of elements in the queue. To maintain integrity, emptyCount may be lower (but never higher) than the actual number of empty places in the queue, and fullCount may be lower (but never higher) than the actual number of items in the queue. Empty places and items represent two kinds of resources, empty boxes and full boxes, and the semaphores emptyCount and fullCount maintain control over these resources.
The binary semaphore useQueue ensures that the integrity of the state of the queue itself is not compromised, for example by two producers attempting to add items to an empty queue simultaneously, thereby corrupting its internal state. Alternatively a Mutex could be used in place of the binary semaphore.
The emptyCount is initially N, fullCount is initially 0, and useQueue is initially 1. The producer does the following repeatedly:
produce:
P(emptyCount)
P(useQueue)
putItemIntoQueue(item)
V(useQueue)
V(fullCount)
The consumer does the following repeatedly:
consume:
P(fullCount)
P(useQueue)
item ← getItemFromQueue()
V(useQueue)
V(emptyCount)
Example.
fullCount is 0, the consumer blocks.emptyCount constraining their entry.useQueue and deposit items in the queue.fullCount is incremented, allowing one consumer to enter its critical section.Note that emptyCount may be much lower than the actual number of empty places in the queue, for example in the case where many producers have decremented it but are waiting their turn on useQueue before filling empty places. Note that emptyCount + fullCount ≤ N always holds, with equality if and only if no producers or consumers are executing their critical sections.
The canonical names P and V come from the initials of Dutch words. V stands for verhogen ("increase"). Several explanations have been offered for P, including proberen for "to test,"[3] passeer for "pass," probeer for "try," and pakken for "grab." However, Dijkstra wrote that he intended P to stand for the portmanteau prolaag,[4] short for probeer te verlagen, literally "try to reduce," or to parallel the terms used in the other case, "try to decrease."[5][6][7] This confusion stems from the fact that the words for increase and decrease both begin with the letter V in Dutch, and the words spelled out in full would be impossibly confusing for those not familiar with the Dutch language.
In ALGOL 68, the Linux kernel,[8] and in some English textbooks, the P and V operations are called, respectively, down and up. In software engineering practice, they are often called wait and signal, acquire and release (which the standard Java library uses[9]), or pend and post. Some texts call them procure and vacate to match the original Dutch initials.
A mutex is essentially the same thing as a binary semaphore, and sometimes uses the same basic implementation. However, the term "mutex" is used to describe a construct which prevents two processes from accessing a shared resource concurrently. The term "binary semaphore" is used to describe a construct which limits access to a single resource.
In many cases a mutex has a concept of an "owner": the process which locked the mutex is the only process allowed to unlock it. In contrast, semaphores generally do not have this restriction, something the producer-consumer example above depends upon.
java.util.concurrent.Semaphore
|
|||||||||||||||||||||||
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)
Dansk (Danish)
n. - semafor, signalmast
v. tr. - signalere med semafor
v. intr. - signalere med semafor
Français (French)
n. - signaux à bras, (Rail) sémaphore
v. tr. - transmettre par signaux à bras
v. intr. - transmettre par signaux à bras
Deutsch (German)
n. - Signalmast, Winken
v. - per Signalmast übermitteln
Ελληνική (Greek)
n. - σηματοφόρος, σηματογράφος, σηματοδοσία, (Η/Υ) διάταξη συντονισμού λειτουργιών
v. - σηματοδοτώ
Português (Portuguese)
n. - semáforo (m)
v. - transmitir mensagem por semáforo
Español (Spanish)
n. - semáforo
v. tr. - señalizar con semáforo
v. intr. - señalizar con semáforo
Svenska (Swedish)
n. - semafor, semaforering
v. - semaforera
中文(简体)(Chinese (Simplified))
臂板信号, 旗语, 信号, 用信号发出信息, 发信号, 打旗语
中文(繁體)(Chinese (Traditional))
n. - 臂板信號, 旗語, 信號
v. tr. - 用信號發出資訊
v. intr. - 發信號, 打旗語
한국어 (Korean)
n. - (철도의) 가로대식 신호기, 시그널, (군대의) 수기 신호
v. tr. - 신호기로 알리다, 신호하다
v. intr. - 수기 신호로 알리다
日本語 (Japanese)
n. - 腕木信号機, 手旗信号
v. - 手旗信号で送る
العربيه (Arabic)
(الاسم) جهاز لتنظيم مرور ألقطارات (فعل) يعطي أشارة لمرور ألقطارات
עברית (Hebrew)
n. - תמרור-רכבת, איתות בדגלים, סימון בזרועות, סמפור
v. tr. - אותת בדגלים
v. intr. - אותת בדגלים
If you are unable to view some languages clearly, click here.