Changeset: fef8e59cf8ad for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fef8e59cf8ad
Modified Files:
        gdk/gdk_utils.c
Branch: Jun2016
Log Message:

When exiting, immediately wait for other threads.
This solves a race condition where the server might not get closed
down correctly, causing a corrupt database.


diffs (41 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1223,20 +1223,32 @@ GDKexiting(void)
        return stopped;
 }
 
+static struct serverthread {
+       struct serverthread *next;
+       MT_Id pid;
+} *serverthread;
+
 void
 GDKprepareExit(void)
 {
+       struct serverthread *st;
+
        if (ATOMIC_TAS(GDKstopped, GDKstoppedLock) != 0)
                return;
        if (GDKvmtrim_id)
                MT_join_thread(GDKvmtrim_id);
+
+       MT_lock_set(&GDKthreadLock);
+       for (st = serverthread; st; st = serverthread) {
+               MT_lock_unset(&GDKthreadLock);
+               MT_join_thread(st->pid);
+               MT_lock_set(&GDKthreadLock);
+               serverthread = st->next;
+               GDKfree(st);
+       }
+       MT_lock_unset(&GDKthreadLock);
 }
 
-static struct serverthread {
-       struct serverthread *next;
-       MT_Id pid;
-} *serverthread;
-
 /* Register a thread that should be waited for in GDKreset.  The
  * thread must exit by itself when GDKexiting() returns true. */
 void
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to