# Reconfiguring a hier\_block2 without locking the top block

**URL:** <https://www.ruby-forum.com/t/reconfiguring-a-hier-block2-without-locking-the-top-block/163067>\
**Category:** GNU Radio\
**Created:** [March 17, 2009, 3:48am UTC](https://www.ruby-forum.com/t/reconfiguring-a-hier-block2-without-locking-the-top-block/163067 "2009-03-17T03:48:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kieran\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7cd45c/32.png) [@Kieran\_B](https://www.ruby-forum.com/u/Kieran_B)\
**Post date:** [March 17, 2009, 3:48am UTC](https://www.ruby-forum.com/t/reconfiguring-a-hier-block2-without-locking-the-top-block/163067/1 "2009-03-17T03:48:58Z")

</div>

Hello all,

Is the code designed so you can .lock() a individual hier\_block2 and  
reconfigure it without having to lock the overall top\_block? IF you do  
have  
to lock the top block, why?

The code below causes a seg fault on my 3.1.3 and 3.2 installations.

Sample code ([http://pastebin.com/d413db7f7](http://pastebin.com/d413db7f7)):

from gnuradio import gr

class h\_block(gr.hier\_block2):  
def **init** (self):  
gr.hier\_block2. **init** (self, “hello”, gr.io\_signature(0, 0, 0),  
gr.io\_signature(0, 0, 0))  
self.source = gr.null\_source(gr.sizeof\_float)  
self.sink = gr.null\_sink(gr.sizeof\_float)  
self.connect(self.source, self.sink)

```
def reconfigure(self):
    self.lock()
    self.disconnect(self.source, self.sink)
    self.source = gr.null_source(gr.sizeof_float)
    self.connect(self.source, self.sink)
    self.unlock()

```

class top\_block(gr.top\_block):  
def **init** (self):  
gr.top\_block. **init** (self)  
self.h\_block = h\_block()  
self.connect(self.h\_block)

if **name** == ‘ **main** ’:  
app = top\_block()  
app.start()  
print “Reconfiguring h\_block”  
app.h\_block.reconfigure()  
app.stop()

Thank you,  
Kieran

---

<div class="post-metadata">

**Author:** ![Kieran\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7cd45c/32.png) [@Kieran\_B](https://www.ruby-forum.com/u/Kieran_B)\
**Post date:** [March 17, 2009, 8:02pm UTC](https://www.ruby-forum.com/t/reconfiguring-a-hier-block2-without-locking-the-top-block/163067/2 "2009-03-17T20:02:45Z")

</div>

On Tue, Mar 17, 2009 at 03:47:54PM +1300, Kieran B. wrote:

> Hello all,
> 
> Is the code designed so you can .lock() a individual hier\_block2 and  
> reconfigure it without having to lock the overall top\_block? IF you do have  
> to lock the top block, why?

You can lock/unlock on anything derived from from hier\_block2 or  
top\_block.

FWIW, your code works for me using the trunk as of r10628.  
That is, it prints “Reconfiguring h\_block”, and then hangs.  
(The hang is a different bug that will be addressed soon.)

> The code below causes a seg fault on my 3.1.3 and 3.2 installations.

If it printed anything before dying, can you please post that?  
Can you generate a backtrace from the segfault using gdb?

Eric

---

<div class="post-metadata">

**Author:** ![Kieran\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7cd45c/32.png) [@Kieran\_B](https://www.ruby-forum.com/u/Kieran_B)\
**Post date:** [March 17, 2009, 10:13pm UTC](https://www.ruby-forum.com/t/reconfiguring-a-hier-block2-without-locking-the-top-block/163067/3 "2009-03-17T22:13:59Z")

</div>

On Wed, Mar 18, 2009 at 8:01 AM, Eric B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> FWIW, your code works for me using the trunk as of r10628.  
> That is, it prints “Reconfiguring h\_block”, and then hangs.  
> (The hang is a different bug that will be addressed soon.)

Is the hang coming from the lock? Since it seems to be crashing once it  
gets  
into an infinite loop while locking.

If it printed anything before dying, can you please post that?

> Can you generate a backtrace from the segfault using gdb?

(Ignore the file name - I added the “Locking” to see where in the  
sequence  
it was crashing)  
sdrts@sdrts:~/test$ python multiple\_top\_block\_test.py  
Reconfiguring h\_block  
Locking  
Segmentation fault  
sdrts@sdrts:~/test$

And backtrace from gdb: (3.1.3 but same thing happens at the same point  
in  
my 3.2 installation)

> > > app.h\_block.reconfigure()

Program received signal SIGSEGV, Segmentation fault.  
[Switching to Thread 0xb7d748c0 (LWP 30961)]  
gr\_hier\_block2::lock (this=0xa012a40) at gr\_hier\_block2.cc:98  
98 gr\_hier\_block2::lock()  
Current language: auto; currently c++  
(gdb) backtrace  
#0 gr\_hier\_block2::lock (this=0xa012a40) at gr\_hier\_block2.cc:98  
#1 0xb7afa023 in gr\_hier\_block2\_detail::lock (this=)  
at gr\_hier\_block2\_detail.cc:369  
#2 0xb7af93f0 in gr\_hier\_block2::lock (this=0xa012a40) at  
gr\_hier\_block2.cc:100  
#3 0xb7afa023 in gr\_hier\_block2\_detail::lock (this=)  
at gr\_hier\_block2\_detail.cc:369  
#4 0xb7af93f0 in gr\_hier\_block2::lock (this=0xa012a40) at  
gr\_hier\_block2.cc:100  
#5 0xb7afa023 in gr\_hier\_block2\_detail::lock (this=)  
at gr\_hier\_block2\_detail.cc:369  
#6 0xb7af93f0 in gr\_hier\_block2::lock (this=0xa012a40) at  
gr\_hier\_block2.cc:100  
#7 0xb7afa023 in gr\_hier\_block2\_detail::lock (this=)  
at gr\_hier\_block2\_detail.cc:369  
#8 0xb7af93f0 in gr\_hier\_block2::lock (this=0xa012a40) at  
gr\_hier\_block2.cc:100

This goes on for a looong time (I stopped after 30,000 lines).

Thank you,  
Kieran
