|
Boost Users : |
Subject: [Boost-users] [Interprocess] Different outputs under bash and gdb
From: Aditya Gadre (agadre_at_[hidden])
Date: 2010-11-23 16:23:10
Dear all,
I have a question about proper use of Boost.Interprocess for sharing
custom C++ classes. I recently started using Boost.Interprocess and have
been successful in sharing boost::array, std::vector<float>,
std::vector< boost::array<float, 2> > etc using
boost::interprocess::managed_shared_memory and
boost::interprocess::allocator.
Currently, I am trying to share a custom matrix class that is used to
hold data in a tabular format. The Matrix class (attached header file
Matrix.hpp) is a simple wrapper class that uses std::vector to store
objects and provides functions to find items using linear and matrix
indexing. I have modified a boost::interprocess example program to try
out sharing the Matrix class (attached file test_matrix_shm.cpp). The
parent process creates a managed memory segment along with a Matrix in
the shared memory. The child process accesses the shared memory and
successfully finds the Matrix object. However, when I run the program
under bash, the output of the child process shows wrong data. However,
if I run the same program under gdb, then every time the child process
shows correct Matrix data as was set by the parent process (please find
sample outputs below). I am really not sure what would cause this
behavior. I would appreciate any input in this regard.
* bash output *
parent process
Matrix size = 2 x 2
0 1
2 3
child process
Matrix size = 2 x 2
-1.2522e-41 -1.25486e-41
-1.2571e-41 -1.25949e-41
child returning
parent returning
* gdb output *
GNU gdb (GDB) SUSE (7.1-3.12)
(gdb) run
Starting program: test_matrix_shm
parent process
Matrix size = 2 x 2
0 1
2 3
Detaching after fork from child process 2548.
child process
Matrix size = 2 x 2
0 1
2 3
child returning
parent returning
Program exited normally.
Thanks
- Aditya
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