X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/143383a2a8535c79e6bad8b54495132ef7792338:/examples/msg/maestro-set/maestro-set.c..53e3b26debedd9ec4e16c8f72d9e476f7e6f82c7:/examples/msg/maestro-set/maestro-set.cpp
diff --git a/examples/msg/maestro-set/maestro-set.c b/examples/msg/maestro-set/maestro-set.cpp
similarity index 75%
rename from examples/msg/maestro-set/maestro-set.c
rename to examples/msg/maestro-set/maestro-set.cpp
index f59ff452f0..c1ab4d27f2 100644
--- a/examples/msg/maestro-set/maestro-set.c
+++ b/examples/msg/maestro-set/maestro-set.cpp
@@ -1,37 +1,37 @@
-/* Copyright (c) 2007-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+/** @addtogroup MSG_examples
+ *
+ * - maestro-set/maestro-set.cpp: Switch the system thread hosting our maestro.
+ * That's a very advanced example in which we move the maestro thread to another process.
+ * Not many users need it (maybe only one, actually), but this example is also a regression test.
+ *
+ * This example is in C++ because we use C++11 threads to ensure that the feature is working as
+ * expected. You can still use that feature from a C code.
+ */
+
#include "simgrid/msg.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-#define _GNU_SOURCE /* See feature_test_macros(7) */
-#include
-#include
-#include /* pid_t */
+#include
-pid_t root_pid;
+std::thread::id root_id;
static void ensure_root_tid() {
- pid_t my_pid = syscall(SYS_gettid);
- xbt_assert(my_pid == root_pid, "I was supposed to be the main thread but %d != %d", my_pid, root_pid);
+ std::thread::id this_id = std::this_thread::get_id();
+ xbt_assert(root_id == this_id, "I was supposed to be the main thread");
XBT_INFO("I am the main thread, as expected");
}
static void ensure_other_tid() {
- pid_t my_pid = syscall(SYS_gettid);
- xbt_assert(my_pid != root_pid, "I was NOT supposed to be the main thread");
+ std::thread::id this_id = std::this_thread::get_id();
+ xbt_assert(this_id != root_id, "I was NOT supposed to be the main thread");
XBT_INFO("I am not the main thread, as expected");
}
-/** @addtogroup MSG_examples
- *
- * - maestro-set/maestro-set.c: Switch the system thread hosting our maestro.
- * That's a very advanced example in which we move the maestro thread to another process.
- * Not many users need it (maybe only one, actually), but this example is also a regression test.
- */
static int sender(int argc, char *argv[])
@@ -66,7 +66,7 @@ static void maestro(void* data)
/** Main function */
int main(int argc, char *argv[])
{
- root_pid = syscall(SYS_gettid);
+ root_id = std::this_thread::get_id();
SIMIX_set_maestro(maestro, NULL);
MSG_init(&argc, argv);