double compute_cost;
do {
- double* msg = mailbox->get<double>();
+ auto msg = mailbox->get_unique<double>();
compute_cost = *msg;
- delete msg;
if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
simgrid::s4u::this_actor::execute(compute_cost);
double compute_cost;
do {
- double* msg = mailbox->get<double>();
+ auto msg = mailbox->get_unique<double>();
compute_cost = *msg;
- delete msg;
if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
simgrid::s4u::this_actor::execute(compute_cost);
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name);
while (true) { // Master forcefully kills the workers by the end of the simulation
- double* msg = mailbox->get<double>();
+ auto msg = mailbox->get_unique<double>();
double compute_cost = *msg;
- delete msg;
simgrid::s4u::this_actor::execute(compute_cost);
}
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name);
while (true) { // Master forcefully kills the workers by the end of the simulation
- double* msg = mailbox->get<double>();
+ auto msg = mailbox->get_unique<double>();
double compute_cost = *msg;
- delete msg;
// simgrid::s4u::this_actor::exec_init(compute_cost)->set_tracing_category(category)->wait();
/* Long form:*/
XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->get_cname());
- const auto* msg1 = mailbox->get<std::string>();
- const auto* msg2 = mailbox->get<std::string>();
- const auto* msg3 = mailbox->get<std::string>();
+ auto msg1 = mailbox->get_unique<std::string>();
+ auto msg2 = mailbox->get_unique<std::string>();
+ auto msg3 = mailbox->get_unique<std::string>();
XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str());
- delete msg1;
- delete msg2;
- delete msg3;
XBT_INFO("I'm done. See you.");
}
}
try {
- auto* answer = mailbox_->get<TrackerAnswer>(GET_PEERS_TIMEOUT);
+ auto answer = mailbox_->get_unique<TrackerAnswer>(GET_PEERS_TIMEOUT);
// Add the peers the tracker gave us to our peer list.
for (auto const& peer_id : answer->getPeers())
if (id != peer_id)
connected_peers.emplace(peer_id, Connection(peer_id));
- delete answer;
} catch (const simgrid::TimeoutException&) {
XBT_DEBUG("Timeout expired when requesting peers to tracker");
return false;
void joinChain()
{
- const auto* msg = me->get<ChainMessage>();
- prev = msg->prev_;
- next = msg->next_;
- total_pieces = msg->num_pieces;
+ auto msg = me->get_unique<ChainMessage>();
+ prev = msg->prev_;
+ next = msg->next_;
+ total_pieces = msg->num_pieces;
XBT_DEBUG("Peer %s got a 'BUILD_CHAIN' message (prev: %s / next: %s)", me->get_cname(),
prev ? prev->get_cname() : nullptr, next ? next->get_cname() : nullptr);
- delete msg;
}
void forwardFile()
{
double compute_cost;
do {
- const auto* msg = mailbox->get<double>();
+ auto msg = mailbox->get_unique<double>();
compute_cost = *msg;
- delete msg;
if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
simgrid::s4u::this_actor::execute(compute_cost);
double compute_cost;
do {
- const auto* msg = mailbox->get<double>();
+ auto msg = mailbox->get_unique<double>();
compute_cost = *msg;
- delete msg;
if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
simgrid::s4u::this_actor::execute(compute_cost);
mailbox_out->put(payload, 1);
/* - ... then wait for the (large) pong */
- const auto* sender_time = mailbox_in->get<double>();
+ auto sender_time = mailbox_in->get_unique<double>();
double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
XBT_INFO("Payload received : large communication (bandwidth bound)");
XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
- delete sender_time;
}
static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
/* - Receive the (small) ping first ....*/
- const auto* sender_time = mailbox_in->get<double>();
+ auto sender_time = mailbox_in->get_unique<double>();
double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
XBT_INFO("Payload received : small communication (latency bound)");
XBT_INFO("Ping time (latency bound) %f", communication_time);
- delete sender_time;
/* - ... Then send a 1GB pong back (bandwidth bound) */
auto* payload = new double(simgrid::s4u::Engine::get_clock());
const char* host_name = simgrid::s4u::this_actor::get_host()->get_cname();
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(args.at(0));
- const auto* payload = mbox->get<struct s_payload>();
- double clock_end = simgrid::s4u::Engine::get_clock();
+ auto payload = mbox->get_unique<struct s_payload>();
+ double clock_end = simgrid::s4u::Engine::get_clock();
XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name,
clock_end - payload->clock_sta);
-
- delete payload;
}
static void launch_communication_worker(s4u_Host* tx_host, s4u_Host* rx_host)
long pending_finalize_messages = peers_count - 1;
while (pending_finalize_messages > 0) {
if (my_mbox->ready()) {
- double start = simgrid::s4u::Engine::get_clock();
- const auto* received = my_mbox->get<std::string>();
- double waiting_time = simgrid::s4u::Engine::get_clock() - start;
+ double start = simgrid::s4u::Engine::get_clock();
+ auto received = my_mbox->get_unique<std::string>();
+ double waiting_time = simgrid::s4u::Engine::get_clock() - start;
xbt_assert(
waiting_time == 0,
"Expecting the waiting time to be 0 because the communication was supposedly ready, but got %f instead",
if (*received == "finalize") {
pending_finalize_messages--;
}
- delete received;
} else {
XBT_INFO("Nothing ready to consume yet, I better sleep for a while");
simgrid::s4u::this_actor::sleep_for(.01);
{
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
XBT_INFO("Wait for the message.");
- const auto* received = mbox->get<std::string>();
+ auto received = mbox->get_unique<std::string>();
XBT_INFO("I got '%s'.", received->c_str());
- delete received;
}
int main(int argc, char* argv[])
{
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
- const auto* received = mbox->get<std::string>();
+ auto received = mbox->get_unique<std::string>();
XBT_INFO("I got a '%s'.", received->c_str());
cont = (*received != "finalize"); // If it's a finalize message, we're done
// Receiving the message was all we were supposed to do
- delete received;
}
}
};
{
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
- const auto* received = mbox->get<std::string>();
+ auto received = mbox->get_unique<std::string>();
XBT_INFO("I got a '%s'.", received->c_str());
cont = (*received != "finalize"); // If it's a finalize message, we're done
// Receiving the message was all we were supposed to do
- delete received;
}
}
};
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
- const auto* received = mbox->get<std::string>();
+ auto received = mbox->get_unique<std::string>();
XBT_INFO("I got a '%s'.", received->c_str());
if (*received == "finalize")
cont = false; // If it's a finalize message, we're done.
- delete received;
}
}
{
ensure_other_tid();
- const auto* payload = simgrid::s4u::Mailbox::by_name("some mailbox")->get<std::string>();
+ simgrid::s4u::Mailbox::by_name("some mailbox")->get_unique<std::string>();
XBT_INFO("Task received");
- delete payload;
}
static void maestro(void* /* data */)
static void coordinator()
{
int CS_used = 0;
- const Message* m = nullptr;
std::queue<simgrid::s4u::Mailbox*> requests;
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
while (true) {
- m = mbox->get<Message>();
+ auto m = mbox->get_unique<Message>();
if (m->kind == Message::Kind::REQUEST) {
if (CS_used) {
XBT_INFO("CS already used. Queue the request.");
CS_used = 0;
}
}
- delete m;
}
}
XBT_INFO("Propositions changed : r=1, cs=0");
}
- const auto* grant = my_mailbox->get<Message>();
+ auto grant = my_mailbox->get_unique<Message>();
if ((id == 1) && (grant->kind == Message::Kind::GRANT)) {
cs = 1;
XBT_INFO("Propositions changed : r=0, cs=1");
}
- delete grant;
-
XBT_INFO("%d got the answer. Sleep a bit and release it", id);
simgrid::s4u::this_actor::sleep_for(1);
static void server()
{
- int* received = nullptr;
+ std::unique_ptr<int> received;
int count = 0;
while (count < N) {
- if (received) {
- delete received;
- received = nullptr;
- }
- received = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
+ received.reset();
+ received = simgrid::s4u::Mailbox::by_name("mymailbox")->get_unique<int>();
count++;
}
int value_got = *received;
int value_got = -1;
simgrid::s4u::Mailbox* mb = simgrid::s4u::Mailbox::by_name("server");
for (int count = 0; count < worker_amount; count++) {
- const auto* msg = mb->get<int>();
+ auto msg = mb->get_unique<int>();
value_got = *msg;
- delete msg;
}
/*
* We assert here that the last message we got (which overwrite any previously received message) is the one from the
XBT_DEBUG("Worker started");
- const auto* payload = mbox->get<double>();
+ auto payload = mbox->get_unique<double>();
count_finished--;
if (count_finished == 0) {
XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s", id, *payload, masternames[id], workernames[id]);
XBT_DEBUG("FLOW[%d] : transferred in %f seconds", id, elapsed_time);
- delete payload;
XBT_DEBUG("Finished");
}
while (true) {
try {
XBT_INFO("Waiting a message on %s", mailbox->get_cname());
- const auto* payload = mailbox->get<double>();
+ auto payload = mailbox->get_unique<double>();
xbt_assert(payload != nullptr, "mailbox->get() failed");
double comp_size = *payload;
- delete payload;
if (comp_size < 0) { /* - Exit when -1.0 is received */
XBT_INFO("I'm done. See you!");
break;
ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME.c_str(), simgrid::s4u::this_actor::get_cname(),
from->get_cname());
- delete from->get<std::string>();
+ from->get_unique<std::string>();
log_action(action, simgrid::s4u::Engine::get_clock() - clock);
}
};
{
auto mbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
while (true) {
- const auto* task = mbox->get<Task>();
+ auto task = mbox->get_unique<Task>();
if (task->name == "finalize") {
- delete task;
break;
}
// creating task and setting its category
->set_name(task->name)
->set_tracing_category(task->category)
->wait();
- delete task;
}
}
TRACE_host_variable_set(my_hostname, "task_computation", 0);
while (true) {
- const auto* task = mailbox->get<Task>();
+ auto task = mailbox->get_unique<Task>();
if (task->name == "finalize") {
- delete task;
break;
}
// adding the task's cost to the variable "task_computation"
->set_name(task->name)
->set_tracing_category(task->category)
->wait();
- delete task;
}
XBT_DEBUG("Exiting now.");
double compute_cost;
do {
- const auto* msg = mailbox->get<double>();
- compute_cost = *msg;
- delete msg;
+ auto msg = mailbox->get_unique<double>();
+ compute_cost = *msg;
if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
simgrid::s4u::this_actor::execute(compute_cost);
std::string("__mig_stage3:") + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")";
while (not received_finalize) {
- const std::string* payload = mbox->get<std::string>();
+ auto payload = mbox->get_unique<std::string>();
if (finalize_task_name == *payload)
received_finalize = true;
-
- delete payload;
}
// Here Stage 1, 2 and 3 have been performed.
XBT_DEBUG("wait for reception of the final ACK (i.e. migration has been correctly performed");
simgrid::s4u::Mailbox* mbox_ctl = simgrid::s4u::Mailbox::by_name(
std::string("__mbox_mig_ctl:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")");
- delete mbox_ctl->get<std::string>();
+ mbox_ctl->get_unique<std::string>();
tx->join();
rx->join();
static int receiver(const char* box_name)
{
auto mb = simgrid::s4u::Mailbox::by_name(box_name);
- const int* payload;
+ std::unique_ptr<int> payload;
- payload = mb->get<int>();
+ payload = mb->get_unique<int>();
MC_assert(*payload == 1);
- delete payload;
- payload = mb->get<int>();
+ payload = mb->get_unique<int>();
MC_assert(*payload == 2);
- delete payload;
return 0;
}
static void commRX()
{
- const std::string* payload = nullptr;
XBT_INFO(" Start RX");
try {
- payload = simgrid::s4u::Mailbox::by_name("comm")->get<std::string>();
+ auto payload = simgrid::s4u::Mailbox::by_name("comm")->get_unique<std::string>();
XBT_INFO(" Receive message: %s", payload->c_str());
} catch (const simgrid::HostFailureException&) {
XBT_INFO(" Receive message: HOST_FAILURE");
XBT_INFO(" Receive message: TRANSFER_FAILURE");
}
- delete payload;
XBT_INFO(" RX Done");
}
static void worker()
{
- const std::string* payload = nullptr;
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("comm");
XBT_INFO("Worker receiving");
try {
- payload = mailbox->get<std::string>();
+ auto payload = mailbox->get_unique<std::string>();
+ XBT_DEBUG("Received message: %s", payload->c_str());
} catch (const simgrid::HostFailureException&) {
XBT_DEBUG("The host has been turned off, this was expected");
- delete payload;
return;
}
static void worker()
{
- const std::string* payload;
simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("jupi");
while (true) {
+ std::unique_ptr<std::string> payload;
try {
- payload = mailbox->get<std::string>();
+ payload = mailbox->get_unique<std::string>();
} catch (const simgrid::HostFailureException&) {
XBT_DEBUG("The host has been turned off, this was expected");
return;
}
if (*payload == "finalize") {
- delete payload;
break;
}
simgrid::s4u::this_actor::execute(5E7);
XBT_INFO("Task \"%s\" done", payload->c_str());
- delete payload;
}
XBT_INFO("I'm done. See you!");
}
XBT_INFO("Mailbox::listen_from() returns %ld (should return my pid, which is %ld)", mailbox->listen_from(),
simgrid::s4u::this_actor::get_pid());
- const std::string* res = mailbox->get<std::string>();
+ auto res = mailbox->get_unique<std::string>();
xbt_assert(*res == "Some data", "Data received: %s", res->c_str());
XBT_INFO("Data successfully received from regular mailbox");
- delete res;
sendComm->wait();
simgrid::s4u::Mailbox* mailbox2 = simgrid::s4u::Mailbox::by_name("mailbox2");
xbt_assert(mailbox2->listen()); // used to break.
XBT_INFO("Task listen works on asynchronous mailboxes");
- res = mailbox2->get<std::string>();
+ res = mailbox2->get_unique<std::string>();
xbt_assert(*res == "More data");
- delete res;
XBT_INFO("Data successfully received from asynchronous mailbox");
}
{
for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
XBT_VERB("waiting for messages");
- int* ptr = box->get<int>();
+ auto ptr = box->get_unique<int>();
int id = *ptr;
XBT_VERB("received messages #%i", id);
- delete ptr;
}
XBT_INFO("Done receiving from %d senders, each of them sending %d messages", nb_sender, nb_message_to_send);
}
static void test_receive(){
for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
XBT_VERB("waiting for messages");
- int* ptr = box->get<int>();
+ auto ptr = box->get_unique<int>();
int id = *ptr;
XBT_VERB("received messages #%i", id);
- delete ptr;
}
XBT_INFO("Done receiving from %d senders, each of them sending %d messages", nb_sender, nb_message_to_send);
}
XBT_INFO("Server waiting for transfers ...");
while (true) {
- const std::string* msg = mailbox->get<std::string>();
+ auto msg = mailbox->get_unique<std::string>();
if (*msg == "finalize") { // Shutdown ...
- delete msg;
break;
} else { // Receive file to save
size_t pos = msg->find(' ');
std::string dest = msg->substr(0, pos);
sg_size_t size_to_write = std::stoull(msg->substr(pos + 1));
write_local_file(dest, size_to_write);
- delete msg;
}
}