This was entirely related to usage of semaphores and solaris implementation. In My case the process 1 was posting before the process 2 could open the shared memory for semaphores. Hence the process two was not getting any post from process 1. I got the above code working with minor changes listed below:
...
//in global space
struct iSema
{
interprocess_semaphore ASync;
interprocess_semaphore BSync;
interprocess_semaphore CSync;
iSema()
:ASync(0), BSync(0), CSync(0)
{}
}*m_Sema;
mapped_region SemaRegion;
#define SHM_SIZE 512
...
...
//in main process 1
try
{
std::size_t ShmSize = SHM_SIZE;
shared_memory_object::remove("xyz"); //remove previous instance
shared_memory_object shm(create_only, "xyz", read_write); //create new
shm.truncate(sizeof(struct iSema));
mapped_region region(shm, read_write); //get into local scope region
SemaRegion.swap(region); //swap with global scope region
m_Sema = new (SemaRegion.get_address()) (struct iSema); //map it
}
catch(exception& e)
{//logging
}
...
//Do some thing
m_Sema->CSync.wait();
m_Sema->ASync.post();
m_Sema->BSync.wait();
...
...
//in main second process
try
{
std::size_t ShmSize = SHM_SIZE;
shared_memory_object shm(open_only, "xyz", read_write);
shm.truncate(sizeof(struct iSema));
mapped_region region(shm, read_write);
SemaRegion.swap(region);
m_Sema = new (SemaRegion.get_address()) (struct iSema);
}
catch(exception& e)
{
//logging
}
m_Sema->CSync.post();
m_Sema->ASync.wait();
m_Sema->BSync.post();
...