Mono alternative for named Mutex(命名互斥体的单声道替代品)
问题描述
在 Windows/.NET 上,可以使用命名的 Mutex 来同步多个进程.不幸的是,Mono 在 Linux 上并不完全支持这一点.他们的 发行说明 说 Linux 不支持此 Windows 功能,并且模拟它是不可靠的.无论如何,似乎最好避免提议的黑客攻击.
On Windows/.NET, a named Mutex can be used to synchronise multiple processes. Unfortunately, Mono doesn't quite support this on Linux. Their release notes say that Linux doesn't support this Windows feature and it would be unreliable to emulate it. It seems best to avoid the proposed hack to enable it anyway.
那么建议的替代方案是什么?我需要让我的程序可以安全地并发运行,只有一小部分需要与其他实例同步.
So what are suggested alternatives? I need to make my program safe to run concurrently, only a short section of it needs to be synchronised with other instances.
该应用程序最终需要部署在带有 Mono 2.10 的 Ubuntu Linux 上,但为了进行测试,如果它也可以在带有 .NET 4 的 Windows 7 上运行,我们将不胜感激.
The application eventually needs to be deployed on Ubuntu Linux with Mono 2.10, but for testing, it would be highly appreciated if it also works on Windows 7 with .NET 4.
推荐答案
更新:
尝试查看 http://aakinshin.net/en/blog/dotnet/namedmutex-on-mono/
旧:
Mono 不支持任何 Windows 原生 IPC.所以你没有命名管道或互斥体.
OLD:
Mono does not support any Windows-native IPC.
So you do not have for example Named Pipes, or Mutexes.
但要在同一进程中同步线程,您可以使用 显式监控类(也用于锁).
But to sync threads in the same process you can use Monitor class explicitly (it also used for lock).
要简单地通知另一个进程,您可以尝试使用 Unix 域套接字.
检查 UnixEndPoint 类.您可以为其指定名称的好处之一(例如命名信号量).
To simply notify another process you can try to use Unix Domain Sockets.
Check UnixEndPoint class for that. One of benefits you can specify name for it (like for named semaphore for example).
您也可以尝试使用自己的文件模拟 Mutex.尝试获得对特定自己文件的独占访问权限.当您拥有该访问权限时 - 您处于关键部分.
Also you can try to emulate Mutex using own file. Try to get exclusive access to specific own file. While you have that access - you are in critical section.
这篇关于命名互斥体的单声道替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:命名互斥体的单声道替代品
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01