discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] usrp2 dtor can throw !


From: Gaetano Mendola
Subject: [Discuss-gnuradio] usrp2 dtor can throw !
Date: Fri, 14 Jan 2011 17:25:42 +0100

Hi all,
the usrp2 destructor can throw an exeption due the fact that while
destroying the
implementation ( usrp2::impl::~impl() ) a stop_bg() is performed.

The stop_bg implementation is:

  void
  usrp2::impl::stop_bg()
  {
    d_bg_running = false;
    d_bg_pending_cond.notify_one(); // FIXME: check if needed
    d_rx_tg.join_all();
  }

indeed the boost::thread_group::join_all is an interruption point for
boost thread.
This can lead to a crash in case an user thread (using boost threads)
receives an
interruption while a stack unwinding is already occurring and an usrp2
is destroyed.

There are two ways to correct the problem:
1) Instanziate a boost::this_thread::disable_interruption inside the stop_bg()
2) or do a try{ } catch() { } inside the impl destructor.

This is very dangerous because normaly the user code acquire a usrp instance
with a boost::shared_ptr, I guess this was done to reliefe the user to
perform an
explicit delete, however due this bug the user is forced to do:

usrp2::usrp2::sptr myDevice = usrp2::usrp2::make("eth1", "", 1024*1024)
...
try {
  myDevice.reset();
}
catch(...) {
}

Regards
Gaetano Mendola

-- 
cpp-today.blogspot.com



reply via email to

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