您现在所在的是:

嵌入式系统

回帖:0个,阅读:964 [上一页] [1] [下一页]
* 帖子主题:

Semaphore(旗语)

1137
xingsharp
文章数:119
年度积分:48
历史总积分:1137
注册时间:2005/3/2
发站内信
08年优秀博客奖
发表于: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

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

31.2002