1 /* synchro_crashtest -- tries to crash the logging mecanism by doing // logs*/
3 /* Copyright (c) 2007 Martin Quinson. 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. */
9 #include "xbt/synchro.h"
11 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
14 int test_amount = 99; /* Up to 999 to not break the logs (and thus the testing mecanism) */
15 int crasher_amount = 99; /* Up to 99 to not break the logs (and thus the testing mecanism) */
16 int *id; /* to pass a pointer to the threads without race condition */
18 int more_info = 0; /* SET IT TO TRUE TO GET MORE INFO */
21 * Some additionnal code to let the father wait the childs
29 /* Code ran by each thread */
30 static void crasher_thread(void *arg)
32 int id = *(int *) arg;
35 for (i = 0; i < test_amount; i++) {
37 INFO10("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
38 test_amount - i, id, id, id, id, id, id, id, id, id);
40 INFO0("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
43 xbt_mutex_acquire(mut_end);
45 xbt_cond_signal(cond_end);
46 xbt_mutex_release(mut_end);
49 int crasher(int argc, char *argv[]);
50 int crasher(int argc, char *argv[])
53 xbt_thread_t *crashers;
55 gras_init(&argc, argv);
57 /* initializations of the philosopher mecanisms */
58 id = xbt_new0(int, crasher_amount);
59 crashers = xbt_new(xbt_thread_t, crasher_amount);
61 for (i = 0; i < crasher_amount; i++)
64 /* setup the ending mecanism */
65 running_threads = crasher_amount;
66 cond_end = xbt_cond_init();
67 mut_end = xbt_mutex_init();
70 for (i = 0; i < crasher_amount; i++) {
71 char *name = bprintf("thread %d", i);
72 crashers[i] = xbt_thread_create(name, &crasher_thread, &id[i],0/*not joinable*/);
77 xbt_mutex_acquire(mut_end);
78 while (running_threads)
79 xbt_cond_wait(cond_end, mut_end);
80 xbt_mutex_release(mut_end);
86 int main(int argc, char *argv[])
90 errcode = crasher(argc, argv);