[interprocess] lock_exception with managed_mapped_file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[interprocess] lock_exception with managed_mapped_file

capsterx
This post has NOT been accepted by the mailing list yet.
FreeBSD 11.0-RELEASE-p1  amd64
I've tried boost 1.57.0 and 1.64.0

I feel like I'm doing something wrong, but this is version of a unit test I boiled down (it works in linux).

If I map in file0, unmap file0, then file1, then file1, and after each mapping find_or_create a lock, lock and unlock it, the last one throws a lock exception (pthread errno 22,  The value specified by mutex is invalid.).
If I map file1, file1, same scenario, I don't get an error.
If I map file1, file0, file1, file, I also don't get an error.
If I map file0, file1, file, I don't get an error.

The below code uses   check_sanity(), but I get the same result with find_or_construct<interprocess_mutex>...


#include <string>
#include <boost/interprocess/managed_mapped_file.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <iostream>

namespace bip = boost::interprocess;

using Shm = boost::interprocess::managed_mapped_file;

Shm create_shm(std::string path, size_t mapping_size)
{
  return bip::managed_mapped_file(
    bip::open_or_create,
    path.c_str(),
    mapping_size + sizeof(bip::interprocess_mutex));
}

void init_shm(Shm & shm) {
  if (!shm.check_sanity()) {
    throw std::runtime_error("SHM sanity check failed");
  }
}

int main()
{
  try {
  // uncomment this or remove the block below
  //auto shm0 = create_shm("/tmp/test1", 500);
  //init_shm(shm0);
  {
    auto shm2 = create_shm("/tmp/test2", 500);
    init_shm(shm2);
  }

  auto shm1 = create_shm("/tmp/test1", 500);
  init_shm(shm1);
  auto shm3 = create_shm("/tmp/test1", 500);
  init_shm(shm3);
  } catch (std::exception & e)
  {
    std::cout << "Got exception: " << e.what() << std::endl;
  }
}
Loading...