# Put a block to sleep

**URL:** <https://www.ruby-forum.com/t/put-a-block-to-sleep/241268>\
**Category:** GNU Radio\
**Created:** [May 21, 2014, 11:54am UTC](https://www.ruby-forum.com/t/put-a-block-to-sleep/241268 "2014-05-21T11:54:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [May 21, 2014, 11:54am UTC](https://www.ruby-forum.com/t/put-a-block-to-sleep/241268/1 "2014-05-21T11:54:46Z")

</div>

Hello everybody,

I want to connect a source to a sink block but there must be a sort of  
synchronization between them. The sink block should ask the source to  
generate data stream on some specific instances. Between these  
instances,  
the source block must put to the sleep or be disabled. How could I do  
this?

I thought it was possible with exchanging messages between these two  
blocks  
by which the sink block send a message to the source to disable or  
enable  
it. But this doesn’t work because the scheduler will remain on the  
source  
after generating only one block of data (I need to generate just one  
block)  
at the start up of the flowgraph!

best,  
Mostafa

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 21, 2014, 12:50pm UTC](https://www.ruby-forum.com/t/put-a-block-to-sleep/241268/2 "2014-05-21T12:50:47Z")

</div>

On Wed, May 21, 2014 at 5:53 PM, Mostafa A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Hello everybody,
> 
> I want to connect a source to a sink block but there must be a sort of  
> synchronization between them. The sink block should ask the source to  
> generate data stream on some specific instances. Between these instances,  
> the source block must put to the sleep or be disabled. How could I do this?

The scheduler takes care of this. You don’t need to worry this.

I thought it was possible with exchanging messages between these two

> blocks by which the sink block send a message to the source to disable or  
> enable it. But this doesn’t work because the scheduler will remain on the  
> source after generating only one block of data (I need to generate just one  
> block) at the start up of the flowgraph!

If you just need to generate only one block of data (one element), then  
you  
may not need gnuradio.

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 21, 2014, 2:54pm UTC](https://www.ruby-forum.com/t/put-a-block-to-sleep/241268/3 "2014-05-21T14:54:36Z")

</div>

On 21.05.2014 11:53, Mostafa A. wrote:

> or enable it. But this doesn’t work because the scheduler will remain on  
> the source after generating only one block of data (I need to generate  
> just one block) at the start up of the flowgraph!

If you just need one block, you can use blocks.head.  
To “keep your block alive”, you can use a heartbeat message: Give your  
block another message port, and use the message strobe to send it  
messages every N ms. Once it’s alive, you can figure out if you need  
your source to send more data.

M

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 22, 2014, 1:23pm UTC](https://www.ruby-forum.com/t/put-a-block-to-sleep/241268/4 "2014-05-22T13:23:41Z")

</div>

It doesn’t work for me!

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 21, 2014, 3:49pm UTC](https://www.ruby-forum.com/t/put-a-block-to-sleep/241268/5 "2014-05-21T15:49:58Z")

</div>

Hi Martin,

_blocks.head_ isn’t appropriate for my case because this is not a test!

I searched for managing a thread, I found this :

[http://www.boost.org/doc/libs/1\_48\_0/doc/html/thread/synchronization.html#thread.synchronization.condvar\_ref](http://www.boost.org/doc/libs/1_48_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref)

which is a part of boost library.

This is exactly what I want, but I don’t know how I could use these  
classes  
in GNURadio!?

The message passing mechanisms in GNURadio needs a block to be alive(as  
far  
as I know), but here I think I should put the block ( or the thread) to  
sleep and wake it up by a signal.
