Skip to content

Named mutex not working on Linux and MacOS when AOT compiling #110348

Closed as duplicate of#48720
@darind

Description

@darind

Description

Acquiring a global named mutex doesn't seem to work on MacOS and Linux when the application is compiled with NativeAOT.

Reproduction Steps

internal static class Program
{
    private static void Main(string[] args)
    {
        using (var mutex = new Mutex(false, "Global\\{604074dc-be47-4a35-b79d-b79eead0c022}"))
        {
            mutex.WaitOne();

            Console.WriteLine("The app is now running...");
            Console.ReadLine();
        }
    }
}

Compile to native using the following:

dotnet publish --configuration Release --runtime osx-x64 --output dist

Expected behavior

The second instance of the program blocks and waits until the first has terminated

Actual behavior

The second instance successfully acquires the mutex.

Regression?

No response

Known Workarounds

No response

Configuration

  • .net 8
  • MacOS and Linux (ubuntu 24)
  • x64

Other information

The same works if the application is not compiled to native code but simply build in release mode:

dotnet build --configuration Release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions