create shared memory segment and semaphore

#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <functional>
#include <utility>
#include <boost/lexical_cast.hpp>
#include <boost/interprocess/sync/named_semaphore.hpp>

namespace bip = boost::interprocess;

int main ()
{
using namespace boost::interprocess;
const char* shmName="cbaWorkflow";
const char* mapName="execution_status";


//Shared memory front-end that is able to construct objects
//associated with a c-string. Erase previous shared memory with the name
//to be used and create the memory segment at the specified address and initialize resources
bip::managed_shared_memory segment
(bip::create_only
,shmName //segment name
,65536); //segment size in bytes

//Note that map<Key, MappedType>'s value_type is std::pair<const Key, MappedType>,
//so the allocator must allocate that pair.
// ShmString is boost::interprocess::basic_string
typedef bip::allocator<char, bip::managed_shared_memory::segment_manager> CharAllocator;
typedef bip::basic_string<char, std::char_traits<char>, CharAllocator> ShmString;

typedef ShmString KeyType;
typedef int MappedType;
typedef std::pair<const ShmString, int> ValueType;

//Alias an STL compatible allocator of for the map.
//This allocator will allow to place containers
//in managed shared memory segments
typedef bip::allocator<ValueType, bip::managed_shared_memory::segment_manager>
ShmemAllocator;

//Alias a map of ints that uses the previous STL-like allocator.
//Note that the third parameter argument is the ordering function
//of the map, just like with std::map, used to compare the keys.
typedef map<KeyType, MappedType, std::less<KeyType>, ShmemAllocator> MyMap;

//Initialize the shared memory STL-compatible allocator
ShmemAllocator alloc_inst (segment.get_segment_manager());

// Create a semaphore all the clients will be using
bip::named_semaphore sem(
bip::open_or_create
,shmName
,1
,0600
);
//Construct a shared memory map.
//Note that the first parameter is the comparison function,
//and the second one the allocator.
//This the same signature as std::map's constructor taking an allocator

sem.wait();
MyMap *mymap =
segment.construct<MyMap>(mapName) //object name
(std::less<ShmString>() //first ctor parameter
,alloc_inst); //second ctor parameter

//Insert data in the map
for(int i = 0; i < 10; ++i){
string tmp="1305"+boost::lexical_cast<string>(i);
ShmString str(tmp.c_str(), segment.get_allocator<ShmString>());
mymap->insert(std::pair<const ShmString, int>(str,0));
}
sem.post();
return 0;
}