Skip to content

Inter-process Mutex doesn't work for processes of different architectures on Apple Silicon #62140

@valco1994

Description

@valco1994

Description

It's impossible to synchronize .NET processes of different architectures (x64 and aarch64) using System.Threading.Mutex on Apple Silicon

Reproduction Steps

Let's create the following simple console application:

using System;
using System.Threading;

class Program {
  static void Main(string[] args)
  {
      Mutex mutex = null;
      try
      {
          mutex = new Mutex(false, "Global\\MyUniqueMutexName");
          mutex.WaitOne();
          Thread.Sleep(TimeSpan.FromSeconds(60));
      }
      catch (Exception ex) { Console.WriteLine(ex); }
      finally { mutex?.ReleaseMutex(); }
  }
}

Then let's build it on Apple Silicon using two toolsets with .NET 6 - for x64 and aarch64.

And then launch them sequentially in any order.

Expected behavior

Both instances of the application run successfully and terminate ~60 seconds after the start of the first one (the second instance waits for the global mutex acquired by the first one).

Actual behavior

The second application is finished intermediately with following message

System.Threading.WaitHandleCannotBeOpenedException: A WaitHandle with system-wide name 'Global\MyUniqueMutexName' cannot be created. A WaitHandle of a different type might have the same name.
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at Program.Main(String[] args) in /Users/Valentin.Grigorev/RiderProjects/GlobalMutexExperiment2/x64App/Program.cs:line 11

Regression?

No response

Known Workarounds

I don't know any workarounds

Configuration

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.6
 OS Platform: Darwin
 RID:         osx.11.0-arm64
 Base Path:   /Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-arm64/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  6.0.100 [/Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-arm64/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.0 [/Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-arm64/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0 [/Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-arm64/shared/Microsoft.NETCore.App]

and

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.6
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-x64/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  6.0.100 [/Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-x64/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.0 [/Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-x64/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0 [/Users/Valentin.Grigorev/Downloads/dotnet-sdk-6.0.100-osx-x64/shared/Microsoft.NETCore.App]

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions