如何在 SimGrid 中创建带有向量的进程?

How to create a process with vector in SimGrid?

我想用 SimGrid 中的数据创建一个流程,所以我这样做了:

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

但是在executor我有一个分割错误:

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;
}

我知道这是因为当 worker 函数结束并且 vector1 消失时 vector1 超出范围,所以 "there is no vector1 data" 在执行程序中。

如何正确操作?

我想你只是想在这里使用一个指针:)

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());
    return 0;
}

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());
    delete data;
    return 0;
}