Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono alternative for named Mutex

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.

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.

like image 688
ygoe Avatar asked Jan 21 '14 19:01

ygoe


1 Answers

UPDATE:
Try to look at http://aakinshin.net/en/blog/dotnet/namedmutex-on-mono/

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).

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).

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.

like image 192
Maxim Avatar answered Nov 14 '22 00:11

Maxim