Jean-Yves Lefort: fix "crash" on exit
mf: pthread_cancel doesn't seem to work correctly on all supported platforms. It apparently causes SGBlockingQueue::pop() to correctly leave the thread on the cancellation point pthread_wait(), but the SGGuard() destructor isn't called, so the queue mutex remains locked. This triggered an assert() on pthread_join(). This patch uses an empty ICAO request as signal for the thread to terminate itself.
This commit is contained in:
parent
8676df6856
commit
ed9e16d001
2 changed files with 12 additions and 5 deletions
|
@ -344,8 +344,7 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
|
|||
FGMetarEnvironmentCtrl::~FGMetarEnvironmentCtrl ()
|
||||
{
|
||||
#if defined(ENABLE_THREADS)
|
||||
thread->cancel();
|
||||
thread->join();
|
||||
thread_stop();
|
||||
#endif // ENABLE_THREADS
|
||||
|
||||
delete env;
|
||||
|
@ -590,8 +589,7 @@ FGMetarEnvironmentCtrl::fetch_data( const string &icao )
|
|||
#if defined(ENABLE_THREADS)
|
||||
if (_error_count++ >= 3) {
|
||||
SG_LOG( SG_GENERAL, SG_WARN, "Stop fetching data permanently.");
|
||||
thread->cancel();
|
||||
thread->join();
|
||||
thread_stop();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -707,12 +705,21 @@ FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m )
|
|||
|
||||
|
||||
#if defined(ENABLE_THREADS)
|
||||
void
|
||||
FGMetarEnvironmentCtrl::thread_stop()
|
||||
{
|
||||
request_queue.push( string() ); // ask thread to terminate
|
||||
thread->join();
|
||||
}
|
||||
|
||||
void
|
||||
FGMetarEnvironmentCtrl::MetarThread::run()
|
||||
{
|
||||
while ( true )
|
||||
{
|
||||
string icao = fetcher->request_queue.pop();
|
||||
if (icao.empty())
|
||||
return;
|
||||
SG_LOG( SG_GENERAL, SG_INFO, "Thread: fetch metar data = " << icao );
|
||||
FGMetarResult result = fetcher->fetch_data( icao );
|
||||
fetcher->result_queue.push( result );
|
||||
|
|
|
@ -240,7 +240,7 @@ private:
|
|||
*/
|
||||
MetarThread* thread;
|
||||
|
||||
|
||||
void thread_stop();
|
||||
#endif // ENABLE_THREADS
|
||||
|
||||
int _error_count;
|
||||
|
|
Loading…
Reference in a new issue