rrdtool plugin: Wait for the `queue thread' to exit..
[collectd.git] / src / rrdtool.c
index 06d9763..7002dcf 100644 (file)
@@ -1052,6 +1052,14 @@ static int rrd_shutdown (void)
        rrd_cache_flush (-1);
        pthread_mutex_unlock (&cache_lock);
 
+       /* Wait for all the values to be written to disk before returning. */
+       if (queue_thread != 0)
+       {
+               pthread_join (queue_thread, NULL);
+               queue_thread = 0;
+               DEBUG ("rrdtool plugin: queue_thread exited.");
+       }
+
        pthread_mutex_lock (&queue_lock);
        do_shutdown = 1;
        pthread_cond_signal (&queue_cond);