Share on Facebook Share on Twitter Email
Answers.com

semaphore

 
Dictionary: sem·a·phore   (sĕm'ə-fôr', -fōr') pronunciation
n.
  1. A visual signaling apparatus with flags, lights, or mechanically moving arms, as one used on a railroad.
  2. A visual system for sending information by means of two flags that are held one in each hand, using an alphabetic code based on the position of the signaler's arms.
tr. & intr.v., -phored, -phor·ing, -phores.
To send (a message) or to signal by semaphore.

[Greek sēma, sign + -PHORE.]

semaphoric sem'a·phor'ic adj.
semaphorically sem'a·phor'i·cal·ly adv.

Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics

Method of visual signaling, usually with flags or lights. Before radio, a semaphore system was widely used to send messages between ships. A person would stand with arms extended, moving two flags to specific angles to indicate letters or numbers. Before the invention of the telegraph, semaphore signaling with lights on high towers was used to transmit messages between distant points; messages were read by telescope. Modern semaphores have included movable arms or rows of light simulating arms, displayed from towers and used to signal railroad trains.

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 iPhone/iTouch

Thesaurus: semaphore
Top

verb

    To communicate by means of such devices as lights or signs: flag1, signal. See express, words.

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

US Military Dictionary: semaphore
Top

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.

 
Columbia Encyclopedia: semaphore
Top
semaphore (sĕm'əfôr'), device for the visible transmission of messages. The marine semaphore, used by day between ships or between a ship and the shore, consists essentially of a post at the top of which are two pivoted arms. The arms are connected by light gearing to two operating levers. Each letter of the alphabet and each numeral is indicated by a different placing of the arms. The system can also be used by the signalman through motions of his own arms, with or without small flags as indicators. In the railroad semaphore a single projecting arm pivoted at one end and attached to a vertical post is devised to take three positions. Horizontal indicates stop, and vertical, all clear; the inclined position indicates that the locomotive may go ahead under control expecting to be stopped. See signaling.


Word Tutor: semaphore
Top
pronunciation

IN BRIEF: n. - An apparatus for visual signaling with lights or mechanically moving arms v. - Send signals by or as if by a device for signaling.

Tutor's tip: This was the final winning word in the 1946 National Spelling Bee.

Wikipedia: Semaphore (programming)
Top
For other uses, see Semaphore.

In computer science, a semaphore is a protected variable or abstract data type which constitutes the classic method for restricting access to shared resources such as shared memory in a parallel programming environment. A counting semaphore is a counter for a set of available resources, rather than a locked/unlocked flag of a single resource. It was invented by Edsger Dijkstra[1]. Semaphores are the classic solution to preventing race conditions in the dining philosophers problem, although they do not prevent resource deadlocks[citation needed].

Contents

Introduction

Semaphores can only be accessed using the following operations. Those marked atomic should not be interrupted (that is, if the system decides that the "turn is up" for the program doing this, it shouldn't stop it in the middle of those instructions) for the reasons explained below.

P(Semaphore s) // Acquire Resource
{
  wait until s > 0, then s := s-1;
  /* Testing and decrementing s must be atomic to avoid race conditions */
}

V(Semaphore s)  // Release  Resource
{
  s := s+1;   /* must be atomic */
}

Init(Semaphore s, Integer v)
{
  s := v;
}

Notice that incrementing the variable s must not be interrupted, and the P operation must not be interrupted after s is found to be greater than 0. This can be done using a special instruction such as test-and-set (if the architecture's instruction set supports it), or (on uniprocessor systems) ignoring interrupts to prevent other processes from becoming active.

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 (uses its turn to do nothing) or maybe sleeps (tells the system not to give it a turn) 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 initialize the semaphore before any requests are made. The P and V operations must be atomic, which means that no process may ever be preempted in the middle of one of those operations to run another operation on the same semaphore.

The canonical names P and V come from the initials of Dutch words. V stands for verhogen, or "increase". Several explanations have been given for P (including proberen for "to test"[2], passeer for "pass", probeer "try", and pakken "grab"), but in fact Dijkstra wrote that he intended P to stand for the made-up word prolaag,[3] short for probeer te verlagen, literally "try-to-reduce", or to parallel the terms used in the other case, "try-to-decrease". [4][5][6] 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 non-Dutch-speakers.

In the programming language ALGOL 68, in the Linux kernel,[7] 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, or acquire and release (which the standard Java library uses [8]), or pend and post. Some texts call them procure and vacate to match the original Dutch initials.

To avoid busy-waiting, a semaphore may have an associated queue of processes (usually a first-in, first out). 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. When processes have different priorities, the queue may be ordered by priority, so that the highest priority process is taken from the queue first.

Analogy

Assume the 'resources' are toilets in a public restroom, and the 'processes' which want access to toilets are people either waiting in a queue for any toilet to be available or people who are already using the toilet. A person sitting outside the toilet keeps track of how many toilets are free at the moment and who should go in next.

The number of free toilets is the value of the semaphore indicating the number of free resources (toilets) available. When a process (person) wants access to a toilet the semaphore (incharge) will tell him whether she has to wait in the queue or whether she can use the toilet. If the toilet is free the person (process) gets the access and the number of free toilets is decreased by 1 (same as P or down operation). It means number of free resources is less by 1. If the number of free toilets is 0 the person (process) has to wait in the queue till it becomes free (it means the process has to sleep till s>0). Once the person uses the toilet (process finishes its work with the resource) the next person can use it. It means the number of free toilets is increased by 1 (this is same as calling V or Up operation). Now s has become greater than 0 and the person waiting (process sleeping) can have access to the toilet (resource).

The process of asking for available toilets (checking if resource is free), updating the number of free toilets (resources), and waiting in the queue should not be disturbed by any other process. This is called atomic action.

The queue is a first in first out queue which means the first person standing in the queue will get a chance to use a free toilet first. However the queue can be arranged if a person standing somewhere in the queue wants to use the toilet urgently (if a process has more priority).

The counting semaphore concept can be extended with the ability of claiming or returning more than one 'unit' from the semaphore. This is indeed the way the classical UNIX semaphore works. The modified P and V operations work like this:

P(Semaphore s, integer howmany)
{
  /* the following two lines must be an 
     atomic operation */
  wait until s >= howmany;
  s := s - howmany;
}

V(Semaphore s, integer howmany)
{
  s := s + howmany; /* must be atomic */
}

To understand why it is better than just calling the simple version of P 'howmany' times consider the following problem. Let's say you have a pool of N resources, say fixed size buffers. You may want to use a counting semaphore initialised to N to keep track of the number of the buffers available. When a process wants to allocate a buffer, it calls P on the semaphore and gets a buffer. If there are no buffers available, a process waits until some other process releases a buffer and invokes V on the semaphore.

Consider that there are two processes that respectively want to acquire K < N and L < N buffers, such that K + L > N. The naïve implementation would have the first process call the simple decrementing variant P on the semaphore K times, and it would have the second process call the simple decrementing variant P on the semaphore L times. However, this approach can lead to a deadlock: Imagine that the operating system allows the first process to run. Then, when the first process has only acquired control of Z buffers (such that Z < K and Z + L > N), the operating system preempts the first process to allow the second process time to run. The second process begins acquiring buffers. However, when the second process acquires (N - Z) buffers, the semaphore becomes 0 and the second process gets suspended to wait for some other process to free up more buffers (because L > N - Z). The operating system eventually allows the first process to resume, continuing its quest to acquire the remaining (K - Z) buffers that it needs. Unfortunately, since the semaphore is 0, the first process cannot complete this task, so it too becomes suspended to wait for some other process to free up more buffers. Neither the first nor the second process can acquire enough buffers to continue, and therefore neither returns any buffers to the pool. Thus, they are stuck in a deadlock situation.

With the modified semaphore version, the first process will ask for K buffers (or more precisely, semaphore units), which it will get in an atomic operation, leaving N-K units on the semaphore. Then the second process arrives, decrements the semaphore down to N-K-L and since that is a negative number, will wait. As the first process releases buffers and increments the semaphore, as soon as the semaphore reaches 0 it means that there are L elements available in the pool, the second process can be woken up and can receive all of its buffers.

It should be noted that the semaphore count is not necessarily equal to the buffers available in the pool. The checking and waiting twice for the s >= 0 condition in P is needed to guarantee that as multiple processes are added to the semaphore's waiting list they do not disturb each other's request: a process does not change the semaphore's count until it is next in the queue. In real implementations it is done without actually activating up the waiting process for the intermediate step.

Semaphores today as used by programmers

Semaphores remain in common use in programming languages that do not intrinsically support other forms of synchronization. They are the primitive synchronization mechanism in many operating systems. The trend in programming language development, though, is towards more structured forms of synchronization, such as monitors (though these advanced structures typically employ semaphores behind the scenes). In addition to their inadequacies in dealing with (multi-resource) deadlocks, semaphores do not protect the programmer from the easy mistakes of taking a semaphore that is already held by the same process, and forgetting to release a semaphore that has been taken.

Example usage

Since semaphores have a count associated with them, they may be employed when multiple threads need to achieve an objective cooperatively. Consider this example:

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."

Apart from a counting semaphore, there is a "blocking semaphore". A blocking semaphore is a semaphore that is initialized to zero. This has the effect that any thread that does a P operation on the semaphore blocks.

Hardware support

The use of semaphores normally requires hardware support to guarantee the atomicity of operations that require it. Computer machine languages typically include instructions that are designed specifically with semaphores in mind. These special instructions carry out a read-modify-write cycle to memory that is not only uninterruptible but excludes all other operations to the same location in memory by any other processors or input/output devices. The special instructions guarantee that a semaphore procedure using them can test and alter a semaphore in a single, atomic operation.

Binary semaphore vs. Mutex

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.

See also

Notes and references

  1. ^ http://www.cs.utexas.edu/users/EWD/transcriptions/EWD01xx/EWD123.html E. W. Dijkstra, Cooperating sequential processes. Technological University, Eindhoven, The Netherlands, September 1965.
  2. ^ Silberschatz, Galvin, & Gagne 8th Ed. p.234
  3. ^ http://www.cs.utexas.edu/users/EWD/ewd00xx/EWD74.PDF
  4. ^ http://www.cs.utexas.edu/users/EWD/transcriptions/EWD00xx/EWD51.html MULTIPROGAMMERING EN DE X8 from the E.W. Dijkstra Archive (in Dutch)
  5. ^ Dijkstra's own translation reads "try-and-decrease", although that phrase might be confusing for those unaware of the colloquial "try-and..."
  6. ^ http://lkml.org/lkml/2005/12/19/34 Linux Kernel Mailing List: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
  7. ^ Kernel hacking howto on linuxgrill.com
  8. ^ java.util.concurrent.Semaphore
  • Silberschatz, Abraham; Galvin, Peter Baer; Gagne, Greg (2008), Operating System Concepts (8th ed.), John Wiley & Sons. Inc, ISBN 978-0-470-12872-5 
  • The Little Book of Semaphores, by Allen B. Downey, Green Tea Press.

External links


Translations: Semaphore
Top

Dansk (Danish)
n. - semafor, signalmast
v. tr. - signalere med semafor
v. intr. - signalere med semafor

Nederlands (Dutch)
seinpaal

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. - σηματοδοτώ

Italiano (Italian)
semaforo

Português (Portuguese)
n. - semáforo (m)
v. - transmitir mensagem por semáforo

Русский (Russian)
семафор

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. - ‮אותת בדגלים‬


 
 

 

Copyrights:

Dictionary. The American Heritage® Dictionary of the English Language, Fourth Edition Copyright © 2007, 2000 by Houghton Mifflin Company. Updated in 2009. Published by Houghton Mifflin Company. All rights reserved.  Read more
Britannica Concise Encyclopedia. Britannica Concise Encyclopedia. © 2006 Encyclopædia Britannica, Inc. All rights reserved.  Read more
Computer Desktop Encyclopedia. THIS COPYRIGHTED DEFINITION IS FOR PERSONAL USE ONLY.
All other reproduction is strictly prohibited without permission from the publisher.
© 1981-2009 Computer Language Company Inc.  All rights reserved.  Read more
Thesaurus. Roget's II: The New Thesaurus, Third Edition by the Editors of the American Heritage® Dictionary Copyright © 1995 by Houghton Mifflin Company. Published by Houghton Mifflin Company. All rights reserved.  Read more
Military History Companion. The Oxford Companion to Military History. Copyright © 2001, 2004 by Oxford University Press. All rights reserved.  Read more
US Military Dictionary. The Oxford Essential Dictionary of the U.S. Military. Copyright © 2001, 2002 by Oxford University Press, Inc. All rights reserved.  Read more
Columbia Encyclopedia. The Columbia Electronic Encyclopedia, Sixth Edition Copyright © 2003, Columbia University Press. Licensed from Columbia University Press. All rights reserved. www.cc.columbia.edu/cu/cup/ Read more
Word Tutor. Copyright © 2004-present by eSpindle Learning, a 501(c) nonprofit organization. All rights reserved.
eSpindle provides personalized spelling and vocabulary tutoring online; free trial Read more
Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Semaphore (programming)" Read more
Translations. Copyright © 2007, WizCom Technologies Ltd. All rights reserved.  Read more