#include <simgrid/modelchecker.h>
#include <simgrid/s4u.hpp>
-#define N 3
+constexpr int N = 3;
XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
static void server()
{
- void* received = nullptr;
- int count = 0;
+ std::unique_ptr<int> received;
+ int count = 0;
while (count < N) {
- if (received) {
- delete static_cast<int*>(received);
- received = nullptr;
- }
- received = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
+ received.reset();
+ received = simgrid::s4u::Mailbox::by_name("mymailbox")->get_unique<int>();
count++;
}
- int value_got = *(static_cast<int*>(received));
+ int value_got = *received;
MC_assert(value_got == 3);
XBT_INFO("OK");
static void client(int id)
{
- int* payload = new int();
- *payload = id;
+ auto* payload = new int(id);
simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload, 10000);
XBT_INFO("Sent!");