From d8961e51ee35ff3a185474e5efe7ff5b8788e84e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 24 Sep 2015 22:23:26 +0200 Subject: [PATCH 1/1] don't fail miserably when raising an exception after simulation shutdown Fix #26 --- include/xbt/module.h | 2 ++ src/simix/smx_global.c | 6 +++--- src/xbt/ex.c | 5 +++++ src/xbt/xbt_main.c | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/xbt/module.h b/include/xbt/module.h index 9405484950..1e2affa877 100644 --- a/include/xbt/module.h +++ b/include/xbt/module.h @@ -15,6 +15,8 @@ SG_BEGIN_DECL() XBT_PUBLIC(void) xbt_init(int *argc, char **argv); XBT_PUBLIC(void) xbt_exit(void); +XBT_PUBLIC_DATA(int) smx_cleaned; +XBT_PUBLIC_DATA(int) xbt_initialized; SG_END_DECL() diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index bd87629577..d3337a3769 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -238,6 +238,7 @@ void SIMIX_global_init(int *argc, char **argv) exit(0); } +int smx_cleaned = 0; /** * \ingroup SIMIX_API * \brief Clean the SIMIX simulation @@ -246,12 +247,11 @@ void SIMIX_global_init(int *argc, char **argv) */ void SIMIX_clean(void) { - static int cleaned = 0; #ifdef TIME_BENCH_PER_SR smx_ctx_raw_new_sr(); #endif - if (cleaned) return; // to avoid double cleaning by java and C - cleaned = 1; + if (smx_cleaned) return; // to avoid double cleaning by java and C + smx_cleaned = 1; XBT_DEBUG("SIMIX_clean called. Simulation's over."); if (!xbt_dynar_is_empty(simix_global->process_to_run) && SIMIX_get_clock() == 0.0) { XBT_CRITICAL(" "); diff --git a/src/xbt/ex.c b/src/xbt/ex.c index e6bbedb923..a54869ff9a 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -148,6 +148,11 @@ void xbt_ex_display(xbt_ex_t * e) XBT_CRITICAL("%s", e->msg); xbt_free(thrower); + if (xbt_initialized==0 || smx_cleaned) { + fprintf(stderr, "Ouch. SimGrid is not initialized yet, or already closing. No backtrace available.\n"); + return; /* Not started yet or already closing. Trying to generate a backtrace would probably fail */ + } + if (!e->bt_strings) xbt_ex_setup_backtrace(e); diff --git a/src/xbt/xbt_main.c b/src/xbt/xbt_main.c index 4923f24b47..e1a234fd83 100644 --- a/src/xbt/xbt_main.c +++ b/src/xbt/xbt_main.c @@ -124,6 +124,7 @@ static void xbt_preinit(void) { static void xbt_postexit(void) { if(!_sg_do_clean_atexit) return; + xbt_initialized--; xbt_backtrace_postexit(); xbt_fifo_postexit(); xbt_dict_postexit(); -- 2.20.1