Mono alternative for titled Mutex

On Windows / .NET, named Mutex can be used to synchronize multiple processes. Unfortunately, Mono does not quite support this on Linux. Their notes suggest that Linux does not support this feature of Windows, and it would be unreliable to imitate it. It is best to avoid the proposed hack in order to enable it anyway.

So what are the alternatives offered? I need my program to be safe to run at the same time, only a short section should be synchronized with other instances.

Ultimately, the application should be deployed to Ubuntu Linux with Mono 2.10, but for testing it would be very useful if it also works on Windows 7 with .NET 4.

+6
source share
1 answer

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

OLD:
Mono does not support any Windows-native IPC. Thus, you do not have, for example, Named Pipes or Mutexes.

But to synchronize threads in the same process, you can explicitly use the Monitor class (it is also used to block).

To simply notify another process , you can try using Unix Domain Sockets .
To do this, consider UnixEndPoint . One of the advantages that you can specify for it (for example, for a semaphore with a name).

You can also try emulating Mutex using your own file. Try exclusive access to a specific file of your own. As long as you have this access, you are in the critical section.

+5
source

All Articles