请问在vxworks5.4中给互斥变量加锁的函数是哪个

ndcsyb 2006-05-31 08:08:25
请问在vxworks5.4中给互斥变量加锁的函数是哪个?比如在vxworks5.5中可用的是pthread_mutex_lock.还有在vxworks5.4有没有与pthread.h相对应的头文件?
...全文
429 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ndcsyb 2006-08-06
  • 打赏
  • 举报
回复
谢谢各位!
olivegames 2006-07-15
  • 打赏
  • 举报
回复
楼上正解
mysear 2006-06-08
  • 打赏
  • 举报
回复
想要申请互斥信号量的话用semMCreate;计数信号量的话用semCCreate;不太明白你用in_pc_cond做什么用,semTake已经保证了操作的原子性,没用必要在semTake(in_pc_cond,WAIT_FOREVER)前后使用互斥信号量
ndcsyb 2006-06-07
  • 打赏
  • 举报
回复
忘说了!我这只是程序的一部分!semTake(in_pc_cond,WAIT_FOREVER)中的in_pc_cond是一个
同步信号量!所以在这地方出现一次!
mysear 2006-06-06
  • 打赏
  • 举报
回复
为何连用了两个semTake(),却只调用了一次semGive
yjf7888 2006-06-01
  • 打赏
  • 举报
回复
semMLib
NAME
semMLib - mutual-exclusion semaphore library

ROUTINES

semMCreate( ) - create and initialize a mutual-exclusion semaphore
semMGiveForce( ) - give a mutual-exclusion semaphore without restrictions



DESCRIPTION
This library provides the interface to VxWorks mutual-exclusion semaphores. Mutual-exclusion semaphores offer convenient options suited for situations requiring mutually exclusive access to resources. Typical applications include sharing devices and protecting data structures. Mutual-exclusion semaphores are used by many higher-level VxWorks facilities.

The mutual-exclusion semaphore is a specialized version of the binary semaphore, designed to address issues inherent in mutual exclusion, such as recursive access to resources, priority inversion, and deletion safety. The fundamental behavior of the mutual-exclusion semaphore is identical to the binary semaphore (see the manual entry for semBLib), except for the following restrictions:

- It can only be used for mutual exclusion.
- It can only be given by the task that took it.
- It may not be taken or given from interrupt level.
- The semFlush( ) operation is illegal.

These last two operations have no meaning in mutual-exclusion situations.


RECURSIVE RESOURCE ACCESS
A special feature of the mutual-exclusion semaphore is that it may be taken "recursively," i.e., it can be taken more than once by the task that owns it before finally being released. Recursion is useful for a set of routines that need mutually exclusive access to a resource, but may need to call each other.

Recursion is possible because the system keeps track of which task currently owns a mutual-exclusion semaphore. Before being released, a mutual-exclusion semaphore taken recursively must be given the same number of times it has been taken; this is tracked by means of a count which is incremented with each semTake( ) and decremented with each semGive( ).

The example below illustrates recursive use of a mutual-exclusion semaphore. Function A requires access to a resource which it acquires by taking semM; function A may also need to call function B, which also requires semM:

SEM_ID semM;

semM = semMCreate (...);


funcA ()
{
semTake (semM, WAIT_FOREVER);
...
funcB ();
...
semGive (semM);
}


funcB ()
{
semTake (semM, WAIT_FOREVER);
...
semGive (semM);
}

mysear 2006-06-01
  • 打赏
  • 举报
回复
可以用semMCreate semTake 和semGive实现啊
ndcsyb 2006-06-01
  • 打赏
  • 举报
回复
这样!把以下的代码转化一下
void SuspendThread(pthread_mutex_t* in_pm_mutex,pthread_cond_t* in_pc_cond)
{
pthread_mutex_lock(in_pm_mutex);
pthread_cond_wait(in_pc_cond,in_pm_mutex);
pthread_mutex_unlock(in_pm_mutex);
}
变成
void SuspendThread(SEM_ID in_pm_mutex,SEM_ID in_pc_cond)
{
semTake(in_pm_mutex,WAIT_FOREVER);
semTake(in_pc_cond,WAIT_FOREVER);
semGive(in_pm_mutex);
}
行吗?编译是能通过的!

2,179

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧