From: Michal Sojka Date: Tue, 23 Jul 2013 19:20:32 +0000 (+0200) Subject: Synchronize external mode in different threads X-Git-Url: https://rtime.felk.cvut.cz/gitweb/ert_linux.git/commitdiff_plain/d08022a70f0af6dcb6d7848610dca24daac8f9e9 Synchronize external mode in different threads Seems to fix the race condition. --- 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(%);