3423|5

61

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

进程间如何做到互斥? [复制链接]

gpio寄存器都是以组的形式出现(一个寄存器对应一组gpio.pin),我们的多个驱动会用到同一组gpio的不同pin来做一些使能复位等控制,那么会出现对不同pin但同组即同寄存器操作的状况吗?在同一进程下,我们可以用线程同步的互斥体来避免冲突。如果是进程呢?进程会遇到这种情况吗?进程是在什么情况下做的切换呢?有可能在执行gpio操作的代码(读-改-写)中间做切换吗?

最新回复

pb help里对CREATEMUTEX的解说。所以只要指定一个同样的名字,就可以实现进程间的互斥了。 A handle to the mutex object indicates success. If the named mutex object existed before the function call, the function returns a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS. Otherwise, the caller created the mutex. NULL indicates failure. To get extended error information, call GetLastError. Two or more processes can call CreateMutex to create the same named mutex. The first process actually creates the mutex, and subsequent processes open a handle to the existing mutex. This enables multiple processes to get handles of the same mutex, while relieving you of the responsibility of ensuring that the creating process is started first. When using this technique, set the bInitialOwner flag to FALSE; otherwise, it can be difficult to be certain which process has initial ownership. Multiple processes can have handles of the same mutex object, enabling use of the object for interprocess synchronization. To provide object sharing, a process can specify the name of a mutex object in a call to the CreateMutex function. Use the CloseHandle function to close the handle. The system closes the handle automatically when the process terminates. The mutex object is destroyed when its last handle has been closed.   详情 回复 发表于 2008-12-15 17:47
点赞 关注

回复
举报

90

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
一样的,CREATEMUTEX。这个是全局的。
 
 

回复

84

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
如果是两个应用程序,怎么定义一个全局的互斥体对象。
 
 
 

回复

51

帖子

0

TA的资源

一粒金砂(初级)

4
 
用有名mutex
CreateMutex的时候有个参数Name
两个应用程序用同一个Name就可以了
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

5
 
有个ID号啊!
 
 
 

回复

80

帖子

0

TA的资源

一粒金砂(初级)

6
 
pb help里对CREATEMUTEX的解说。所以只要指定一个同样的名字,就可以实现进程间的互斥了。

A handle to the mutex object indicates success. If the named mutex object existed before the function call, the function returns a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS. Otherwise, the caller created the mutex. NULL indicates failure. To get extended error information, call GetLastError.

Two or more processes can call CreateMutex to create the same named mutex. The first process actually creates the mutex, and subsequent processes open a handle to the existing mutex. This enables multiple processes to get handles of the same mutex, while relieving you of the responsibility of ensuring that the creating process is started first. When using this technique, set the bInitialOwner flag to FALSE; otherwise, it can be difficult to be certain which process has initial ownership.

Multiple processes can have handles of the same mutex object, enabling use of the object for interprocess synchronization. To provide object sharing, a process can specify the name of a mutex object in a call to the CreateMutex function.

Use the CloseHandle function to close the handle. The system closes the handle automatically when the process terminates. The mutex object is destroyed when its last handle has been closed.
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表