Boost logo

Boost Users :

Subject: [Boost-users] [Interprocess] error_code_t = 9 (already_exists_error) while opening a fixed_managed_shared_memory
From: Gaetan Gaumer (gaetan.gaumer_at_[hidden])
Date: 2011-05-19 11:52:40


Hello Ion and other Interprocess users,
we are currently working with fixed_managed_shared_memory segments and
we have a strange behavior while opening existing segments.
Sometimes (we did not found the exact scenario yet...), when we try to
open a fixed_managed_shared_memory
in open_only mode with the code below, we get an
interprocess_exception with the an error_code_t = 9 (
already_exists_error ).

        try{
                managedSharedMemorySegment = new
fixed_managed_shared_memory(boost::interprocess::open_only,
memorySegmentName, memorySegmentMappingAdress);
        }catch (boost::interprocess::interprocess_exception e){
                return e.get_error_code();
        }

A first sight this error_code seems very strange, because in open_only
mode the segment is intended to already exists
so that should not be an error.

Walking the code I found in the mapped_region constructor the
following code which trigger the exception :
522: //Check for fixed mapping error
   if(address && (old_base != address)){
      error_info err = system_error_code();
      this->priv_close();
      throw interprocess_exception(err);
   }

It seems that the mmap function returns an address different that the
given one, which is considered an error.

So I have two questions :
1) Do you have an idea why the mmap function maps the segment at a
different address from the provided one, knowing that this address
is the one returned from code below on another process (so should be valid) ?

        try{
                managedSharedMemorySegment = new
fixed_managed_shared_memory(boost::interprocess::create_only,
memorySegmentName, memorySegmentSize);
                memorySegmentMappingAdress = managedSharedMemorySegment->get_address();
        }catch (boost::interprocess::interprocess_exception e){
                return e.get_error_code();
        }

2) In the mapped_region constructor, when a non null address value is
given as a parameter, could we use the MAP_FIXED flag to force
the mmap function to map the segment at the provided address ?

Thank you for reading and for your help.
Gaëtan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net