Boost logo

Boost :

From: Harold Pirtle (harold.pirtle_at_[hidden])
Date: 2007-02-09 15:00:26


Ion Gaztañaga wrote:
> Hi Glenn,
>
>
>> Since interprocess isn't in the official tarball yet i've been working
>> with the head version from CVS. Whether or not emulation is used is
>> determined by the value in _POSIX_THREAD_PROCESS_SHARED. In a 2.6.17
>> kernel that I'm running on another system the value is 200112L so indeed
>> the native mutexes and condition variables are used. The system that I
>> was having a problem with has a 2.6.9 kernel and the
>> _POSIX_THREAD_PROCESS_SHARED value of -1; corresponding to "not supported".
>>
>
> Thanks for the information and the patch. I've just uploaded it to CVS.
>
> Regards,
>
> Ion
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
>
Hey Ion, I am getting seg faults running the following interprocess code
using the latest boost cvs distro. Conditions work properly using the
old shmem libs but I think something must have changed since then to
cause this. The seg fault happens in the atomic function atomic_dec32.
I'm running kernel 2.6.9-42 if that helps. If I'm doing something wrong
here, please let me know but this has worked in the past.

Thanks,
Harold

//client code follows...
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/sync/mutex_family.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/interprocess/sync/interprocess_condition.hpp>

using namespace boost::interprocess;

class MyClass
{
public:
  interprocess_condition sent_condition;
  interprocess_condition received_condition;
  interprocess_mutex mutex;
};

int main ()
{

  managed_shared_memory* psegment = new managed_shared_memory(
               open_or_create,
               "MySharedMemory", //segment name
               256000000); //segment size in bytes

  MyClass *instance = psegment->find_or_construct<MyClass>
                      ("MyClass") /*name of the object*/
                      ();
 
  scoped_lock<mutex_family::mutex_type> lock(instance->mutex);
  std::cout << "Waiting on Server..." << std::endl;
  instance->sent_condition.wait(lock);
 
  instance->received_condition.notify_all();

  return 0;
}

//server code follows...

#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/sync/mutex_family.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/interprocess/sync/interprocess_condition.hpp>

using namespace boost::interprocess;

class MyClass
{
public:
  interprocess_condition sent_condition;
  interprocess_condition received_condition;
  interprocess_mutex mutex;
};

int main ()
{

 managed_shared_memory* psegment = new managed_shared_memory(
               open_or_create,
               "MySharedMemory", //segment name
               256000000); //segment size in bytes

  MyClass *instance = psegment->find_or_construct<MyClass>
                      ("MyClass") /*name of the object*/
                      ();
             
  instance->sent_condition.notify_all();
 
  scoped_lock<mutex_family::mutex_type> lock(instance->mutex);
  std::cout << "Waiting on Client..." << std::endl;
  instance->received_condition.wait(lock);
 
  psegment->destroy<MyClass>("MyClass");

  shared_memory_object::remove("MySharedMemory");
 
  return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk