# Re: Sharing variable

**URL:** <https://www.ruby-forum.com/t/re-sharing-variable/242086>\
**Category:** GNU Radio\
**Created:** [May 26, 2015, 8:38am UTC](https://www.ruby-forum.com/t/re-sharing-variable/242086 "2015-05-26T08:38:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [May 26, 2015, 8:38am UTC](https://www.ruby-forum.com/t/re-sharing-variable/242086/1 "2015-05-26T08:38:36Z")

</div>

* * *

Discuss-gnuradio mailing list  
removed\_email\_address@domain.invalid  
[https://lists.gnu.org/mailman/listinfo/discuss-gnuradio](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 26, 2015, 8:53am UTC](https://www.ruby-forum.com/t/re-sharing-variable/242086/2 "2015-05-26T08:53:48Z")

</div>

Hello Marcus,

In your original reply you said that variable sharing was a python  
concept,  
So I wrote my block in python.

I would like to do something like the block “variable” or the “probe  
signal” block that shares a variable will all blocks in GNUradio

I want to do a block that changes the samp\_rate or the center frequency  
automatically if a condition is true inside my block.

Thanks

Luis

2015-05-26 8:37 GMT+02:00 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 26, 2015, 9:17am UTC](https://www.ruby-forum.com/t/re-sharing-variable/242086/3 "2015-05-26T09:17:10Z")

</div>

I’m a bit confused; Luis and Anil, are the two of you working on the  
same project?  
I might have oversimplified when I said it’s a python concept: GRC  
variables are actually quite a handy tool that GRC brings, and GNU Radio  
contains quite some blocks to make use of it. However,

> I would like to do something like the block “variable” or the “probe  
> signal” block that shares a variable will all blocks in GNUradio  
> There is no such thing as “sharing”; if you change something for example  
> in a QT GUI range slider, and that changes the parametrization of  
> another block, then there’s an underlying callback/signalling  
> architecture that will, when the slider changes, call the appropriate  
> setter on the other block.  
> In fact, this depends on the GUI framework you’re using, if I’m not  
> mistaken (i.e. QT offers the callback/slot signalling functionality, and  
> GRC just “connects” QT slots to functions of the top block). The  
> function probe block is a terrible, terrible thing in production: if  
> really just polls the function and consumes CPU for nothing; I like it  
> for debugging purposes, and nothing else, since it’s asynchronous, gives  
> no guarantees on actual update rate, is CPU-hungry…

You can get a call-on-event behaviour by giving your block something  
like the following:

class Luis\_class …  
…  
def set\_callback(self, callable):  
self.\_callme = callable  
def work(…):  
…  
if condition:  
self.\_callme(newvalue)

and doing something like

myblock = Luis\_class(…)  
multiply = blocks.multiply\_const\_ff(1.0);  
…  
myblock.set\_callback(lambda x: multiply.set\_k(x))

in your top\_block (or wherever you set up your flow graph)

However, I’d strongly discourage you to do that! Seriously, that’s  
ignoring core functionality of GNU Radio, breaking what I consider  
contracts, will be hard to debug, have terrible multithreading issues,  
undetermined sample-time timing…

> I want to do a block that changes the samp\_rate or the center  
> frequency automatically if a condition is true inside my block.  
> That doesn’t sound like you should be using the GRC variable mechanism  
> at all. Just use message passing or stream tags, both of which were  
> invented for exactly this kind of thing.

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 26, 2015, 11:06am UTC](https://www.ruby-forum.com/t/re-sharing-variable/242086/4 "2015-05-26T11:06:29Z")

</div>

Thank you for your reply Marcus, I don’t work with Anil.

I am going to implement the message passing solutions .

Luis

2015-05-26 8:57 GMT+02:00 Marcus Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 26, 2015, 3:27pm UTC](https://www.ruby-forum.com/t/re-sharing-variable/242086/5 "2015-05-26T15:27:10Z")

</div>

I didn’t actually read this entire thread, so hopefully I’m not  
providing  
useless info, but you might want to check out how the OFDM codes share  
the  
equaliser state between blocks.

Cheers,  
Martin

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 26, 2015, 9:28am UTC](https://www.ruby-forum.com/t/re-sharing-variable/242086/6 "2015-05-26T09:28:17Z")

</div>

That would be a typical usage scenario for stream tags (because the  
estimate can actually be “attached” to specific sample). I recommend  
going through [1] Chaper 1 to 5, where 5.2 explains the usage of stream  
tags.

Best regards,  
Marcus  
[1] [https://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorials](https://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorials)
