1 /* synchro_crashtest -- tries to crash the logging mechanism by doing parallel logs*/
3 /* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "simgrid/msg.h"
11 #include <stdio.h> /* snprintf */
13 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
15 const int test_amount = 99; /* Up to 99 to not break the logs (and thus the testing mechanism) */
16 const int crasher_amount = 99; /* Up to 99 to not break the logs (and thus the testing mechanism) */
17 int *id; /* to pass a pointer to the threads without race condition */
19 int more_info = 0; /* SET IT TO TRUE TO GET MORE INFO */
21 /* Code ran by each thread */
22 static void* crasher_thread(void *arg)
24 int id = *(int *) arg;
26 for (int i = 0; i < test_amount; i++) {
28 XBT_INFO("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
29 test_amount - i, id, id, id, id, id, id, id, id, id);
31 XBT_INFO("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
38 /* initializations of the philosopher mechanisms */
39 id = xbt_new0(int, crasher_amount);
40 xbt_os_thread_t* crashers = xbt_new(xbt_os_thread_t, crasher_amount);
42 for (int i = 0; i < crasher_amount; i++)
46 for (int i = 0; i < crasher_amount; i++) {
48 snprintf(name, sizeof name, "thread %d", i);
49 crashers[i] = xbt_os_thread_create(name, &crasher_thread, &id[i], NULL );
53 for (int i = 0; i < crasher_amount; i++)
54 xbt_os_thread_join(crashers[i],NULL);
62 int main(int argc, char *argv[])
64 MSG_init(&argc, argv);