3 /* synchro_crashtest -- tries to crash the logging mecanism by doing // logs*/
5 /* Copyright (c) 2007 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "xbt/synchro.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(synchro_crashtest, "Logs of this example");
16 int test_amount = 99; /* Up to 999 to not break the logs (and thus the testing mecanism) */
17 int crasher_amount = 99; /* Up to 99 to not break the logs (and thus the testing mecanism) */
18 int *id; /* to pass a pointer to the threads without race condition */
20 int more_info = 0; /* SET IT TO TRUE TO GET MORE INFO */
23 * Some additionnal code to let the father wait the childs
31 /* Code ran by each thread */
32 static void crasher_thread(void *arg)
34 int id = *(int *) arg;
37 for (i = 0; i < test_amount; i++) {
39 INFO10("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",
40 test_amount - i, id, id, id, id, id, id, id, id, id);
42 INFO0("XXX (XX|XX|XX|XX|XX|XX|XX|XX|XX)");
45 xbt_mutex_acquire(mut_end);
47 xbt_cond_signal(cond_end);
48 xbt_mutex_release(mut_end);
51 int crasher(int argc, char *argv[]);
52 int crasher(int argc, char *argv[])
55 xbt_thread_t *crashers;
57 gras_init(&argc, argv);
59 /* initializations of the philosopher mecanisms */
60 id = xbt_new0(int, crasher_amount);
61 crashers = xbt_new(xbt_thread_t, crasher_amount);
63 for (i = 0; i < crasher_amount; i++)
66 /* setup the ending mecanism */
67 running_threads = crasher_amount;
68 cond_end = xbt_cond_init();
69 mut_end = xbt_mutex_init();
72 for (i = 0; i < crasher_amount; i++) {
73 char *name = bprintf("thread %d", i);
74 crashers[i] = xbt_thread_create(name, &crasher_thread, &id[i]);
79 xbt_mutex_acquire(mut_end);
80 while (running_threads)
81 xbt_cond_wait(cond_end, mut_end);
82 xbt_mutex_release(mut_end);
88 int main(int argc, char *argv[])
92 errcode = crasher(argc, argv);