Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further untangle the msg_process creation by using a default value for auto_restart
[simgrid.git] / teshsuite / simix / stack_overflow / stack_overflow.c
1 /* stack_overflow -- simple program generating a stack overflow          */
2
3 /* Copyright (c) 2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #include "simgrid/simix.h"
10 #include "xbt/log.h"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "my log messages");
13
14 static unsigned collatz(unsigned c0, unsigned n)
15 {
16   unsigned x;
17   if (n == 0) {
18     x = c0;
19   } else {
20     x = collatz(c0, n - 1);
21     if (x % 2 == 0)
22       x = x / 2;
23     else
24       x = 3 * x + 1;
25   }
26   return x;
27 }
28
29 static int master(int argc, char *argv[])
30 {
31   XBT_INFO("Launching our nice bugged recursive function...");
32   unsigned i = 1;
33   while (i <= 0x80000000u) {
34     i *= 2;
35     unsigned res = collatz(i, i);
36     XBT_VERB("collatz(%u, %u) returned %u", i, i, res);
37   }
38   return 0;
39 }
40
41 int main(int argc, char *argv[])
42 {
43   SIMIX_global_init(&argc, argv);
44
45   xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]);
46
47   SIMIX_function_register("master", master);
48   SIMIX_create_environment(argv[1]);
49   simcall_process_create("master", master, NULL, sg_host_by_name("Tremblay"), 0, NULL, NULL);
50   SIMIX_run();
51
52   return 0;
53 }