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 */
22 * Some additionnal code to let the father wait the childs
30 /* Code ran by each thread */
31 static void crasher_thread(void *arg) {
35 for (i=0; i<test_amount; i++) {
36 INFO10("%03d (%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d|%02d)",test_amount-i,id,id,id,id,id,id,id,id,id);
39 xbt_mutex_acquire(mut_end);
41 xbt_cond_signal(cond_end);
42 xbt_mutex_release(mut_end);
45 int crasher (int argc,char *argv[]);
46 int crasher (int argc,char *argv[]) {
48 xbt_thread_t *crashers;
50 gras_init(&argc,argv);
52 /* initializations of the philosopher mecanisms */
53 id = xbt_new0(int,crasher_amount);
54 crashers = xbt_new(xbt_thread_t,crasher_amount);
56 for (i=0; i<crasher_amount; i++)
59 /* setup the ending mecanism */
60 running_threads = crasher_amount;
61 cond_end = xbt_cond_init();
62 mut_end = xbt_mutex_init();
65 for (i=0; i<crasher_amount; i++) {
66 char *name = bprintf("thread %d",i);
67 crashers[i] = xbt_thread_create(name,&crasher_thread,&id[i]);
72 xbt_mutex_acquire(mut_end);
73 while (running_threads)
74 xbt_cond_wait(cond_end,mut_end);
75 xbt_mutex_release(mut_end);
81 int main(int argc, char *argv[]){
84 errcode=crasher(argc,argv);