Changeset: 793a10443612 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=793a10443612
Modified Files:
        MonetDB/src/gdk/gdk_utils.mx
Branch: Oct2010
Log Message:

Properly wait for GDKvmtrim thread to finish.
A small step in the process to cleanup out threads usage.


diffs (74 lines):

diff -r eb0949baa606 -r 793a10443612 MonetDB/src/gdk/gdk_utils.mx
--- a/MonetDB/src/gdk/gdk_utils.mx      Tue Nov 02 15:59:48 2010 +0100
+++ b/MonetDB/src/gdk/gdk_utils.mx      Wed Nov 03 14:15:48 2010 +0100
@@ -92,6 +92,8 @@
 #define VALGRIND_FREELIKE_BLOCK(addr, rzB)
 #endif
 
+static int GDKstopped = 1;
+
 @}
 @+ Monet configuration file
 Parse a possible MonetDB.conf file (either in the default location
@@ -1487,6 +1489,7 @@
 #ifdef HAVE_POSIX_FADVISE
 static str highload_name[] = { "idle", "low", "medium", "high", "extreme" };
 
+static MT_Id GDKvmtrim_id;
 static int membits = 0;
 static void
 GDKvmtrim(void *limit)
@@ -1503,7 +1506,13 @@
        }
        do {
                stream *fp = NULL;
-               MT_sleep_ms(highload ? 500 : 5000);
+               int t;
+               /* sleep using catnaps so we can exit in a timely fashion */
+               for (t = highload ? 500 : 5000; t > 0; t -= 50) {
+                       MT_sleep_ms(50);
+                       if (GDKstopped)
+                               return;
+               }
                /* check for runtime overruling */
                if (GDK_vm_trim == 0) {
                        highload = 0;
@@ -1678,11 +1687,8 @@
 #endif
 
 #ifdef HAVE_POSIX_FADVISE
-       if (!GDKembedded && GDK_vm_trim) {
-               MT_Id t;
-
-               MT_create_thread(&t, GDKvmtrim, &GDK_mem_maxsize, 
MT_THR_DETACHED);
-       }
+       if (!GDKembedded && GDK_vm_trim)
+               MT_create_thread(&GDKvmtrim_id, GDKvmtrim, &GDK_mem_maxsize, 
MT_THR_JOINABLE);
 #endif
 
        return 1;
@@ -1693,11 +1699,9 @@
 the transient BATs should be removed.
 The buffer pool manager takes care of this.
 @h
-gdk_export int GDKstopped;
 gdk_export int GDKnr_threads;
 
 @c
-int GDKstopped = 1;
 int GDKnr_threads = 0;
 
 @h
@@ -1710,7 +1714,11 @@
 {
        gdk_set_lock(GDKthreadLock, "GDKexit");
        if (GDKstopped == 0) {
-               GDKstopped++;   /* shouldn't there be a lock here? */
+               GDKstopped = 1; /* shouldn't there be a lock here? */
+#ifdef HAVE_POSIX_FADVISE
+               if (!GDKembedded && GDK_vm_trim)
+                       MT_join_thread(GDKvmtrim_id);
+#endif
                GDKnrofthreads = 0;
                gdk_unset_lock(GDKthreadLock, "GDKexit");
 
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to