- char mailbox[80];
- char taskname[80];
-
- std::string mbox_name = std::string("receiver-") + std::to_string(i % receivers_count);
- mbox = simgrid::s4u::Mailbox::byName(mbox_name);
- snprintf(mailbox,79, "receiver-%ld", i % receivers_count);
- snprintf(taskname,79, "Task_%d", i);
-
- /* Create a communication */
- simgrid::s4u::CommPtr comm = mbox->put_async((void*)mailbox, msg_size);
- XBT_INFO("Send to receiver-%ld Task_%d", i % receivers_count, i);
- }
-
- for (int i = 0; i < receivers_count; i++) {
- char mailbox[80];
- char* payload = xbt_strdup("finalize");
- snprintf(mailbox, 79, "receiver-%d", i);
- simgrid::s4u::CommPtr comm = mbox->put_async((void*)payload, 0);
- XBT_INFO("Send to receiver-%d finalize", i);
- }
+ std::string msg_content = std::string("Message ") + std::to_string(i);
+ // Copy the data we send: the 'msg_content' variable is not a stable storage location.
+ // It will be destroyed when this actor leaves the loop, ie before the receiver gets the data
+ std::string* payload = new std::string(msg_content);