]> git.mxchange.org Git - flightgear.git/commitdiff
Jean-Yves Lefort: fix "crash" on exit
authormfranz <mfranz>
Tue, 7 Mar 2006 10:26:25 +0000 (10:26 +0000)
committermfranz <mfranz>
Tue, 7 Mar 2006 10:26:25 +0000 (10:26 +0000)
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.

src/Environment/environment_ctrl.cxx
src/Environment/environment_ctrl.hxx

index f4bf66e88a92f056723be6e180ab46ee920714a1..b6e8db5864fc0b01564f1b2d4eedb255ae334f0e 100644 (file)
@@ -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 );
index f2266305c1c52422d65bc15563258f1374f0cbc4..aee0a368bbf75b54ca5f81c1b2e055ff80f731e8 100644 (file)
@@ -240,7 +240,7 @@ private:
      */
     MetarThread* thread;
 
-
+    void thread_stop();
 #endif // ENABLE_THREADS
 
     int _error_count;