vtl: fix possible race condition when terminating external program
authorRobin Gareus <robin@gareus.org>
Thu, 28 Mar 2013 22:32:02 +0000 (23:32 +0100)
committerRobin Gareus <robin@gareus.org>
Thu, 28 Mar 2013 22:32:02 +0000 (23:32 +0100)
gtk2_ardour/system_exec.cc

index 889b1565adaa578428becf92f6308c4bd4bf59ab..44fed48c12f01e269960eedf03337f960f5c1c3e 100644 (file)
@@ -409,6 +409,7 @@ SystemExec::make_argp(std::string args) {
 void
 SystemExec::terminate ()
 {
+       ::pthread_mutex_lock(&write_lock);
        close_stdin();
        if (pid) {
                ::usleep(100000);
@@ -428,6 +429,8 @@ SystemExec::terminate ()
 
        wait();
        if (thread_active) pthread_join(thread_id_tt, NULL);
+       thread_active = false;
+       ::pthread_mutex_unlock(&write_lock);
 }
 
 int
@@ -626,6 +629,7 @@ SystemExec::close_stdin()
        ::close(pin[1]);
        ::close(pout[0]);
        ::close(pout[1]);
+       pin[1] = - 1; // mark as closed
 }
 
 int