Search code examples
c#.netlinuxsemaphore

Run semaphore on linux c#


I am running semaphore on linux and is generating the following error:

"Exception": {"ClassName": "System.PlatformNotSupportedException", "Message": "The named version of this synchronization primitive is not supported on this platform.", "Data": null, "InnerException": null, "HelpURL ": null," StackTraceString ":" at System.Threading.Semaphore.CreateSemaphoreCore (Int32 initialCount, Int32 maximumCount, String name, Boolean & createdNew) \ n at System.Threading.Semaphore..ctor (Int32 initialCount, Int32 maximumCount, String name, Boolean & createdNew) \ n at System.Threading.Semaphore..ctor (Int32 initialCount, Int32 maximumCount, String name) \ n "," RemoteStackTraceString ": null," RemoteStackIndex ": 0," ExceptionMethod ": null," HResult ": - 2146233031," Source ":" System.Private.CoreLib "," WatsonBuckets ": null},

Can someone help me?


Solution

  • Linux doesn't support named synchronization primitives, so neither does .NET Core.

    https://github.com/dotnet/runtime/issues/5211

    UPDATE Based on comments

    As of .NET 5, named semaphores are still unsupported. I haven't tested other primitives.

    NET 6 update

    Named semaphores are still not supported, but named Mutexes works fine at least for MacOS

    enter image description here