互斥(在静态库中)
我有一个静态库来访问数据库。它有一个函数readMaximum()
。
readMaximum() 从 DB 中读取最大值。该函数是线程安全的(使用互斥体)。
但问题是:
有两个进程A.exe和B.exe;两者都是用静态库编译的。
有什么办法可以实现进程A.exe和B.exe之间的互斥,这样当两个进程同时调用函数readMaximum()
时,只允许一个进程进入关键部分?
附言。我不想更改数据库/架构/表的任何属性。
I have a static library to access a Database. It has a function readMaximum()
.
readMaximum() reads a maximum value from DB. This function is thread safe (using mutex).
But problem is :
There are two processes A.exe and B.exe; both are compiled with the static library.
Is there any way where I can implement mutual exclusion between process A.exe and B.exe, so that when function readMaximum()
is called by two processes at same time, only one is allow to go into the critical section?
PS. I would not like to change any property of the DB/Schema/Table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 CreateMutex() 创建一个命名的全局互斥体。名称前加上“Global\”前缀。
Use CreateMutex() to created a named global mutex. Prefix the name with "Global\".
您可以使用命名信号量。它对所有进程都是可见的,并且可以控制该行为。
You could use a named semaphore. It is visible to all processes and can control that behavior.
POSIX 具有可以在进程之间共享的互斥体。
POSIX has mutexes which can be shared among the processes.