1 /* synchro_crashtest -- tries to crash the logging mecanism by doing // logs*/
3 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/synchro.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
15 int test_amount = 99; /* Up to 999 to not break the logs (and thus the testing mecanism) */
16 int crasher_amount = 99; /* Up to 99 to not break the logs (and thus the testing mecanism) */
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 */
22 * Some additionnal code to let the father wait the childs
30 /* Code ran by each thread */
31 static void crasher_thread(void *arg)
33 int id = *(int *) arg;
36 for (i = 0; i < test_amount; i++) {
38 INFO10("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
39 test_amount - i, id, id, id, id, id, id, id, id, id);
41 INFO0("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
44 xbt_mutex_acquire(mut_end);
46 xbt_cond_signal(cond_end);
47 xbt_mutex_release(mut_end);
50 int crasher(int argc, char *argv[]);
51 int crasher(int argc, char *argv[])
54 xbt_thread_t *crashers;
56 gras_init(&argc, argv);
58 /* initializations of the philosopher mecanisms */
59 id = xbt_new0(int, crasher_amount);
60 crashers = xbt_new(xbt_thread_t, crasher_amount);
62 for (i = 0; i < crasher_amount; i++)
65 /* setup the ending mecanism */
66 running_threads = crasher_amount;
67 cond_end = xbt_cond_init();
68 mut_end = xbt_mutex_init();
71 for (i = 0; i < crasher_amount; i++) {
72 char *name = bprintf("thread %d", i);
74 xbt_thread_create(name, &crasher_thread, &id[i],
75 0 /*not joinable */ );
80 xbt_mutex_acquire(mut_end);
81 while (running_threads)
82 xbt_cond_wait(cond_end, mut_end);
83 xbt_mutex_release(mut_end);
89 int main(int argc, char *argv[])
93 errcode = crasher(argc, argv);