discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Deleting a block in C++


From: Johnathan Corgan
Subject: Re: [Discuss-gnuradio] Deleting a block in C++
Date: Wed, 13 Jun 2012 07:59:16 -0700

On Fri, Jun 8, 2012 at 11:03 AM, Alexandru Csete <address@hidden> wrote:
 
Is there a smart way to delete a GNU Radio block in C++?
Until now I have been using the shared_ptr().reset() method but it
seems to me that it will only call the destructor if the parent
top_block has not been run.

"Don't do that."

The reference count in the smart pointer is designed to increment and decrement according to usage and scoping.  Calling reset() is reserved for very special situations.

The reason the destructor doesn't get called is that the flowgraph structure itself (created by the call to connect() ) internally stores a copy of the pointer; thus, the reference count never goes to zero.  Resetting it manually is an invitation to a future segfault.
 
This gives me problems when I try to delete and recreate a hardware
input block (e.g. gr-audio input) where the new device can be the same
as the old one, in which case it will report "device busy".

[...]

Perhaps these hardware input blocks are coded incorrectly and should
close the device in their stop() method? Or is there something else we
can do?


You've pegged the real issue.  It's probably a good idea to make start() and stop() do the actual hardware acquisition and release.  I expect this is not trivial, but would be a great improvement in how those blocks can be used.

Johnathan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]