发表于:2008/12/31 13:19:00
#0楼
1、mdk-rtx中的semaphore
routine
attributes
description
os_sem_init
initializes a semaphore object.
os_sem_send
sends a signal (token) to the semaphore.
os_sem_wait
waits for a signal (token) from the semaphore.
isr_sem_send
sends a signal (token) to the semaphore.
note
the semaphore management routines enable you to use semaphores to synchronize the activities of the various tasks and to protect shared variables from corruption.
2、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:
to control access to a shared device between tasks. a printer is a good example. you dont 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.
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 semaphores 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.
3、不错的semaphore powerpoint 教程
semaphores.pdf
----------------------------------------------
此篇文章从博客转发
原文地址: Http://blog.gkong.com/more.asp?id=73249&Name=zjcsharp