Dynare++: fix bug in new threading code

At the end of a thread, we must first notify the main thread waiting on the
condition variable, then unlock the mutex. We must do these two operations in
that order, otherwise there is a possibility of having the main process
destroying the condition variable before the thread tries to notify it (if all
other threads terminate at the same time and bring the counter down to zero).
For that reason, we cannot use std::notify_all_at_thread_exit().

Bug introduced in commit 752a02a3.
5 jobs for master in 1114 minutes and 31 seconds (queued for 2 seconds)
Status Job ID Name Coverage
  Build
passed #2651
build_binaries

00:10:11

passed #2652
build_doc

00:02:18

 
  Test
passed #2655
test_dynare++

00:10:29

passed #2653
testsuite_matlab

00:55:24

failed #2654
allowed to fail
testsuite_octave_auto

17:28:55

 
Name Stage Failure
failed
testsuite_octave_auto Test The script exceeded the maximum execution time set for the job
|     * shock_decomposition/ls2003_plot.mod -  2693.219360
| * observation_trends_and_prefiltering/MCMC/Trend_no_prefilter_MC.mod - 2673.386899
| * measurement_errors/fs2000_corr_me_ml_mcmc/fs2000_corr_ME.mod - 2537.648884
| * estimation/TaRB/fs2000_tarb.mod - 2526.985198

Makefile:1312: recipe for target 'check-octave' failed
make: *** [check-octave] Error 1
make: Leaving directory '/home/gitlab-runner/builds/2084817d/0/Dynare/dynare/tests'
ERROR: Job failed: execution took longer than 6h0m0s seconds