gpt4 book ai didi

c++ - 多用户信号量

转载 作者:可可西里 更新时间:2023-11-01 14:46:00 25 4
gpt4 key购买 nike

我想要实现的目标:我想将我的应用程序的实例计数为固定数量。如果启动了更多应用程序实例,它应该只作为“查看器”工作

她是示例应用程序的代码

boost named_semaphore example

问题:如果所有进程仅从一个用户启动,它工作正常但是如果我用另一个用户启动应用程序,我会得到一个安全异常!!(不允许访问)

有人可以给我指出正确的方向,boost 文档在这个主题上有点欠缺 ;-)
必须设置哪些权限才能允许所有其他登录用户进行访问?

最佳答案

我找到了解决方案

看起来 Boost 的文档还不错 :-/ http://www.boost.org/doc/libs/1_47_0/doc/html/boost/interprocess/permissions.html

只需要通过权限,设置为“无限制”即可

boost::interprocess::permissions permtest;
permtest.set_unrestricted();
_getch();
boost::interprocess::named_semaphore
the_semphore(boost::interprocess::open_or_create,"test_semaphore",3,permtest);

关于c++ - 多用户信号量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7403347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com