From d08022a70f0af6dcb6d7848610dca24daac8f9e9 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Tue, 23 Jul 2013 21:20:32 +0200 Subject: [PATCH] Synchronize external mode in different threads Seems to fix the race condition. --- ert_linux/ert_linux_main.tlc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ert_linux/ert_linux_main.tlc b/ert_linux/ert_linux_main.tlc index e9c4545..516c8f1 100644 --- a/ert_linux/ert_linux_main.tlc +++ b/ert_linux/ert_linux_main.tlc @@ -91,6 +91,10 @@ */ int simulationFinished = 0; + %if extMode == 1 + /* Indication that the base rate thread has started */ + sem_t ext_mode_ready; + %endif %endfunction %function printfunc() Output @@ -138,6 +142,7 @@ %if extMode == 1 % + CHECKE(sem_post(&ext_mode_ready)); %endif clock_gettime(CLOCK_MONOTONIC, &next); @@ -222,6 +227,7 @@ %if extMode == 1 /* External mode */ rtERTExtModeParseArgs(argc, argv); + CHECKE(sem_init(&ext_mode_ready, 0, 0)); %else (void)(argc); (void *)(argv); @@ -261,6 +267,7 @@ %if extMode == 1 /* External mode */ + CHECKE(sem_wait(&ext_mode_ready)); while(rtmGetErrorStatus(%_M) == NULL && !rtmGetStopRequested(%_M)) { rtExtModeOneStep(rtmGetRTWExtModeInfo(RT_MDL), NUMST, (boolean_T *)&rtmGetStopRequested(RT_MDL)); usleep(%); -- 2.39.2