命名互斥体的单声道替代品

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.

这篇关于命名互斥体的单声道替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)