Interprocess anonymous mutex hangs with Apple Silicon

Open
#176 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp

Research direction

Start with the minimal reproducer in boost_interprocess.cpp and run the listed cleanup and arm64/x86_64 commands on the M1 environment. Inspect the managed_shared_memory and interprocess_mutex paths involved in the architecture-dependent shared mutex state; done means both execution orders print "Critical section" without hanging.

Written by the indexing model from the issue text.

Description

Hi, boost interprocess anonymous mutex seems not to be handling well in ARM64 of Apple Silicon.

#include <iostream>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/sync/interprocess_mutex.hpp>

using namespace boost::interprocess;

int main() {
    try{
        managed_shared_memory managed_shm{open_or_create, "shm", 1024};
        interprocess_mutex *mtx =
            managed_shm.find_or_construct<interprocess_mutex>("mtx")();

        mtx->lock();
        std::cout << "Critial section" << std::endl;
        mtx->unlock();
    } catch (const boost::interprocess::interprocess_exception &e) {
        std::cerr << "Interprocess exception thrown: " << e.what() << std::endl;
        _exit(1);
    }
}

Compilation steps followed

clang++ -std=c++17 -arch arm64 boost_interprocess.cpp -I<BOOST_HOME> -o boost_interprocess_arm64 # For arm64 only build
clang++ -std=c++17 -arch x86_64 boost_interprocess.cpp -I<BOOST_HOME> -o boost_interprocess_x64 # For x64 only build 

Expected Behavior
Both the instantiations should work and print Critical Section.

What was observed
When arm64 build is executed first, it works fine, but when x64 build is executed, the subsequent arm64 execution hangs.

Steps to reproduce

  • rm /tmp/boost_interprocess/shm
  • ./boost_interprocess_x64
  • ./boost_interprocess_arm64

Environment tested on

  • MacBook Air (M1, 2020)
  • MacOS Monterey 12.3.1
  • Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Dominant language
C++
Stars
185
Forks
131
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/interprocess

All issues in boostorg/interprocess

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.