Slide 1 Slide 2 Slide 3 Slide 4 Slide 5 Slide 6 Slide 7 Slide 8 Slide 9 Slide 10 Slide 11 Product List
SYS/BIOS Semaphores Slide 2

In the previous module that covered tasks, TI talked a bit about semaphores and how tasks use them to block while waiting for an event to occur or a resource to become available. There are other SYS_BIOS API calls that a task can pend on, such as Mailbox_pend, but ultimately they all use the Semaphore module to do this. Each semaphore that is created will always have a count associated with it, and this count will always be zero or greater. The two basic calls that change or modify this count are Semaphore_pend() and Semaphore_post(): Semaphore_post() increments the count and Semaphore_pend() decrements the count. Here are a few examples. The first example, the designer has created a semaphore called “mySem” and it has a count of 0, calling Semaphore_post() will increment its count to 1. In the second example, the designer has created Semaphore_pend(), the count of mySem decrements back to 0. One should mention here that there are actually two broad classes of semaphores: counting and binary. Binary semaphores can only have a count of either 0 or 1, Counting semaphores can have a count of any number of 0 or greater. When a semaphore is created, one of the parameters passed to the create call is the semaphore MODE, which says which of these two types of semaphores is being created. In this next example, the designer has a semaphore that has a count of 1. If this is a counting semaphore, calling Semaphore_post() will increment the value from 1 to 2. However, if this was a binary semaphore, calling Semaphore_post() on a semaphore with a value of 1 will not change the count.

PTM Published on: 2012-07-19