]> rtime.felk.cvut.cz Git - ert_linux.git/commitdiff
Synchronize external mode in different threads
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 23 Jul 2013 19:20:32 +0000 (21:20 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 23 Jul 2013 19:20:32 +0000 (21:20 +0200)
Seems to fix the race condition.

ert_linux/ert_linux_main.tlc

index e9c4545db223f3cd6918bd670d32d8462bfa654e..516c8f18f03911716f5679a2b5380a82b9bddf9d 100644 (file)
    */
   int simulationFinished = 0;
 
+  %if extMode == 1
+    /* Indication that the base rate thread has started */
+    sem_t ext_mode_ready;
+  %endif
 %endfunction
 
 %function printfunc() Output
 
     %if extMode == 1
       %<SLibGenERTExtModeInit()>
+      CHECKE(sem_post(&ext_mode_ready));
     %endif
 
     clock_gettime(CLOCK_MONOTONIC, &next);
     %if extMode == 1
       /* External mode */
       rtERTExtModeParseArgs(argc, argv);
+      CHECKE(sem_init(&ext_mode_ready, 0, 0));
     %else
       (void)(argc);
       (void *)(argv);
 
     %if extMode == 1
       /* External mode */
+      CHECKE(sem_wait(&ext_mode_ready));
       while(rtmGetErrorStatus(%<modelName>_M) == NULL && !rtmGetStopRequested(%<modelName>_M)) {
         rtExtModeOneStep(rtmGetRTWExtModeInfo(RT_MDL), NUMST, (boolean_T *)&rtmGetStopRequested(RT_MDL));
        usleep(%<FEVAL("uint32", fundamentalStepSize * 1000000)>);