Roma  Karageorgievich Roma Karageorgievich - 2 months ago 6
C++ Question

How to create a process with vector in SimGrid?

I want to create a process with data in SimGrid, so I do this:

int worker(int argc, char *argv[])
{
vector<string> vector1;
vector1.push_back("word");
MSG_process_create("x", executor, &vector1, MSG_host_self());
return 0;
}


But in
executor
I have a segmentation error:

int executor(int argc, char* argv[]){
MSG_process_sleep(10);
vector<string> *data = (vector<string>*) MSG_process_get_data(MSG_process_self());
XBT_INFO("%s", data->front().c_str());
return 0;
}


I know that it happened because
vector1
goes out of scope when
worker
function ends and
vector1
dissappered, so "there is no vector1 data" in executor.

How to do it properly?

Answer

I think you just want to use a pointer here :)

int worker(int argc, char *argv[]) { vector<string>* vector1 = new vector<string>(); vector1->push_back("word"); MSG_process_create("x", executor, vector1, MSG_host_self()); free(vector1); return 0; }