diff options
author | Thomas Tsou <ttsou@vt.edu> | 2012-03-17 15:02:32 -0400 |
---|---|---|
committer | Alexander Chemeris <Alexander.Chemeris@gmail.com> | 2013-06-24 01:51:02 +0400 |
commit | 5f13377b83bc5bfafaf6b150a4b507f190cee585 (patch) | |
tree | 9e64451a2bd9c399e62dc9da45f32cce571d6fc3 /Transceiver52M/multiTRX.cpp | |
parent | a6ca73ca67b2a66f46be4bafd5ebf397a3c0a2af (diff) |
multi-arfcn, trx: handle thread exiting on shutdown
Previous approach was to allow stack unwinding to take care
shutdown and thread ending, which was unpredictable and
occasionally segfault. Attempt to shutdown more gracefully.
There are thread cancellation points in the transceiver code
using pthread_testcancel(), but the thread abstraction library
does not allow direct access to the pthread variables. This
prevents thread shutdown through pthread_cancel(). To get
around this, use boolean status values in the receive socket
service loops and main drive loop.
The socket read calls will block indefinitly, so shutdown
may cause the socket implementation to throw a SocketError
exception. Use of timeout values with reads does not seem to
work correctly or reliably, so catch the exception and ignore
if it occurs on shutdown.
The following error may appear as the socket is shutdown while
the Transceiver is blocking on read().
DatagramSocket::read() failed: Bad file descriptor
So be it; the API doesn't allow us to do any more.
Signed-off-by: Thomas Tsou <ttsou@vt.edu>
Diffstat (limited to 'Transceiver52M/multiTRX.cpp')
-rw-r--r-- | Transceiver52M/multiTRX.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Transceiver52M/multiTRX.cpp b/Transceiver52M/multiTRX.cpp index a68f234..8ce9ae0 100644 --- a/Transceiver52M/multiTRX.cpp +++ b/Transceiver52M/multiTRX.cpp @@ -105,7 +105,15 @@ int main(int argc, char *argv[]) sleep(1); } - LOG(NOTICE) << "Shutting down transceiver..."; + LOG(NOTICE) << "Shutting down transceivers..."; + trx0->shutdown(); + trx1->shutdown(); + trx2->shutdown(); + + /* + * Allow time for threads to end before we start freeing objects + */ + sleep(2); delete trx0; delete trx1; |