From 2aded1af5e55dca76c0b9cd4476b083b8fd8d3f7 Mon Sep 17 00:00:00 2001
From: Jiří Pinkava <j-pi@seznam.cz>
Date: Tue, 17 Mar 2015 23:32:35 +0100
Subject: runtime: fix wait() race condition

Func. wait() should wait until all work is completed, but should not
exit when block is locked()/unlocked() for flow-graph reconfiguration.

It is unprobable, but during unlock() thread context might be switched
after stop() is called but before new thread are executed by scheduller.
This can cause exit from wait() when it is called (eg. from Python
wrapper).

Call of stop() is moved into lock(), no new work should be started on
locked block and this gives threads some time to finish before join()
is called from unlock().
---
 gnuradio-runtime/lib/top_block_impl.h | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'gnuradio-runtime/lib/top_block_impl.h')

diff --git a/gnuradio-runtime/lib/top_block_impl.h b/gnuradio-runtime/lib/top_block_impl.h
index 67395e0c35..1ac5136ddf 100644
--- a/gnuradio-runtime/lib/top_block_impl.h
+++ b/gnuradio-runtime/lib/top_block_impl.h
@@ -82,10 +82,12 @@ namespace gr {
     gr::thread::mutex d_mutex;    // protects d_state and d_lock_count
     tb_state d_state;
     int d_lock_count;
+    boost::condition_variable d_lock_cond;
     int d_max_noutput_items;
 
   private:
     void restart();
+    void wait_for_jobs();
   };
 
 } /* namespace gr */
-- 
cgit v1.2.3