Keil Logo Arm Logo

GENERAL: WHAT ARE SEMAPHORES?

QUESTION

What are semaphores and how would I use them?

ANSWER

There are several types of semaphores (the basic idea behind each type is the same):

  • Binary
  • Counting
  • Mutex

Semaphores are typically used in one of two ways:

  1. To control access to a shared device between tasks. A printer is a good example. You don't want 2 tasks sending to the printer at once, so you create a binary semaphore to control printer access. When a device wishes to print, it attempts to "take" the semaphore. If the semaphore is available, the task gets to print. If the semaphore is not available, the task will have to wait for the printer.
  2. Task synchronization. By tasks taking and giving the same semaphore, you can force them to perform operations in a desired order.

Counting semaphores are used when you might have multiple devices (like 3 printers or multiple memory buffers).

Binary semaphores 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).

Mutex semaphores are optimized for use in controlling mutually exclusive access to a resource. There are several implementations of this type of semaphore.

SEE ALSO

Last Reviewed: Thursday, March 1, 2007


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

ARM’s Privacy Policy has been updated. By continuing to use our site, you consent to ARM’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.

Acquisition of ARM Holdings plc. by SoftBank Group Corp.

We are pleased to inform you that on 5 September 2016, SoftBank Group Corp. acquired ARM Holdings Plc. ARM will continue to operate as an independent business within the SoftBank group.

Any current agreements between ARM Ltd (or other ARM group companies, as applicable) you / your company remain in effect as between the parties, and the parties will continue to be bound by and perform the obligations in such agreements. If you have any queries please direct these to ARMSoftbank-Notifications@arm.com.