core when using managed shared memory -- file based
I have a client and server set up where the client would write to the
shared memory via a managed memory vector. And then the server would read
that shared memory via the managed mapped file.
It works for most situations.
However, I just ran into a situation where the client -- writing to the
vector, crashes.
and I am trying to figure out what caused the crash.
Below are the client (writer) and the server (reader) source code.... as
close as to the current.
Any insights as to why the vector.push_back() crashed? (this is happening
on RH 5.9 64 bit OS.. but the code is compiled for 32 bit.)
client:
#include <iostream>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
#include "fileheader.h"
int main() {
std::string data = "Hello";
char myinput[1024];
printf("enter number of count \n");
scanf("%s", &myinput);
printf("You entered %s \n", myinput);
data = myinput;
int count = std::atoi(myinput);
for (int counter = 0; counter < count; counter ++) {
try {
std::string tmpPath =
"/var/tmp/log/testfile/ManagedMappedFile";;
printf("temp directory: %s \n", tmpPath.c_str());
managed_mapped_file segment(open_or_create,
tmpPath.c_str(), SHARED_MEMORY_SIZE);
printf("initialized managed shared memory \n");
BString bstrData(segment.get_segment_manager());
bstrData = "hello world";
StrAllocator
alloc_init(segment.get_segment_manager());
printf("ALLOCATED memory successfully\n");
BStrVector *myvec =
segment.find_or_construct<BStrVector> (SHARED_VECTOR_NAME)(alloc_init);
myvec->push_back(bstrData);
segment.flush();
printf("inserted mystring into shmvector %d\n",
counter);
} catch (boost::interprocess::bad_alloc e) {
printf("we caught bad alloc\n");
printf("explanation: %s\n", e.what());
printf("error code: %d\n", e.get_error_code());
printf("native: %d\n", e.get_native_error());
break;
} catch (...) {
printf("caught unknown exception\n");
}
}
printf("wrote number");
return 0;
}
contents of fileheader.h
#ifndef FILEHEADER_H_
#define FILEHEADER_H_
#include
participants (1)
-
Sean K