【问题标题】:Run semaphore on linux c#在linux c#上运行信号量
【发布时间】:2020-11-27 02:41:12
【问题描述】:

我在 linux 上运行信号量并产生以下错误:

“Exception”:{“ClassName”:“System.PlatformNotSupportedException”,“Message”:“此平台不支持此同步原语的命名版本。”,“Data”:null,“InnerException”:null , "HelpURL": null," StackTraceString ":" 在 System.Threading.Semaphore.CreateSemaphoreCore (Int32 initialCount, Int32 maximumCount, String name, Boolean & createdNew) \n 在 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},

有人可以帮我吗?

【问题讨论】:

  • 你真的需要一个有名字的吗?
  • 我需要它,因为它会根据特定的令牌锁定。示例:1 - abcd123 - 运行 2 - abcd123 - 锁定 3 - 7895aa - 运行
  • 您可以将信号量存储在全局ConcurrentDictionary<string, SemaphoreSlim>,键是名称。

标签: c# .net linux semaphore


【解决方案1】:

Linux 不支持命名同步原语,因此 .NET Core 也不支持。

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

更新 基于 cmets

从 .NET 5 开始,仍不支持命名信号量。我没有测试过其他原语。

【讨论】:

  • 您可能想要编辑您的帖子,因为命名的 Mutexes 现在可以在 Linux 中使用。 github.com/dotnet/coreclr/pull/5030
  • @julealgon 源代码还有SupportedOSPlatformAttribute("windows"),在Ubuntu下测试一下PlatformNotSupportedException是怎么扔的。 github.com/dotnet/runtime/blob/main/src/libraries/…
  • 我认为你误会了埃里克。最新版本绝对支持 Linux 上的命名互斥锁。我不认为那是文件的实际位置(尽管我自己找不到)。
  • @julealgon 你试过了吗?
  • 我没有亲自尝试过,不,但我已经阅读了至少一份报告,该报告是几天前我在研究这个问题时在 Linux 上积极使用命名互斥锁的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-20
  • 2014-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多