7

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.

2
  • You could write a C (or C++) wrapper and glue code for Mono around some Linux synchronization primitives (see Posix semaphores and sem_overview(7) etc...) Commented Jan 21, 2014 at 19:23
  • Actually I don't know how to glue Mono, I can just use it, with C#. Also this wouldn't be cross-platform at all.
    – ygoe
    Commented Jan 21, 2014 at 20:05

1 Answer 1

5

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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.