Changeset: 2e71e4d2ac9e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2e71e4d2ac9e
Modified Files:
gdk/gdk.h
gdk/gdk_utils.c
monetdb5/mal/mal.c
sql/backends/monet5/sql_scenario.c
sql/server/sql_mvc.c
sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
Branch: default
Log Message:
join on 'waitfor' threads before killing workers. This way we properly exist a
mserver.
diffs (157 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2455,6 +2455,7 @@ VALptr(const ValRecord *v)
typedef struct threadStruct {
int tid; /* logical ID by MonetDB; val == index into
this array + 1 (0 is invalid) */
+ int waitfor; /* waitfor on exit */
MT_Id pid; /* physical thread id (pointer-sized) from the
OS thread library */
str name;
ptr data[THREADDATA];
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1244,8 +1244,9 @@ GDKreset(int status)
{
MT_Id pid = MT_getpid();
Thread t, s;
- int i;
+ if (ATOMIC_TAS(GDKstopped, GDKstoppedLock) != 0)
+ return ;
if( GDKkey){
BBPunfix(GDKkey->batCacheid);
GDKkey = 0;
@@ -1256,17 +1257,15 @@ GDKreset(int status)
}
if (GDKvmtrim_id)
MT_join_thread(GDKvmtrim_id);
- /* first give the other threads a chance to exit properly*/
- for (i = 0; i < 10 && GDKnrofthreads; i++) {
- MT_lock_set(&GDKthreadLock);
- for (t = GDKthreads, s = t + THREADS; t < s; t++)
- if (t->pid && t->pid != pid)
- break;
- MT_lock_unset(&GDKthreadLock);
- if (t == s) /* no other threads? */
- break;
- MT_sleep_ms(CATNAP);
- }
+
+ MT_lock_set(&GDKthreadLock);
+ for (t = GDKthreads, s = t + THREADS; t < s; t++)
+ if (t->pid && t->pid != pid && t->waitfor) {
+ MT_lock_unset(&GDKthreadLock);
+ MT_join_thread(t->pid);
+ MT_lock_set(&GDKthreadLock);
+ }
+ MT_lock_unset(&GDKthreadLock);
if (status == 0) {
/* they had there chance, now kill them */
@@ -1277,11 +1276,11 @@ GDKreset(int status)
if (t->pid != pid) {
fprintf(stderr, "#GDKexit: killing
thread %d\n", MT_kill_thread(victim));
+ GDKnrofthreads --;
}
- GDKnrofthreads --;
}
}
- assert(GDKnrofthreads == 0);
+ assert(GDKnrofthreads <= 1);
/* all threads ceased running, now we can clean up */
#if 0
/* we can't clean up after killing threads */
@@ -1324,6 +1323,7 @@ GDKreset(int status)
MT_lock_unset(&GDKthreadLock);
//gdk_system_reset(); CHECK OUT
}
+ MT_global_exit(status);
}
void
@@ -1333,10 +1333,7 @@ GDKexit(int status)
/* no database lock, so no threads, so exit now */
exit(status);
}
- if (ATOMIC_TAS(GDKstopped, GDKstoppedLock) == 0) {
- GDKreset(status);
- MT_global_exit(status);
- }
+ GDKreset(status);
MT_exit_thread(-1);
}
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -141,7 +141,7 @@ void mserver_reset(void){
mal_client_reset();
mal_module_reset();
mal_module_reset();
- mal_linker_reset();
+ mal_linker_reset();
mal_resource_reset();
mal_runtime_reset();
mal_scenario_reset();
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -252,11 +252,11 @@ SQLinit(void)
throw(SQL, "SQLinit", "Catalogue initialization failed");
SQLinitialized = TRUE;
MT_lock_unset(&sql_contextLock);
- if (MT_create_thread(&sqllogthread, (void (*)(void *)) mvc_logmanager,
NULL, MT_THR_DETACHED) != 0) {
+ if (MT_create_thread(&sqllogthread, (void (*)(void *)) mvc_logmanager,
NULL, MT_THR_JOINABLE) != 0) {
throw(SQL, "SQLinit", "Starting log manager failed");
}
#if 0
- if (MT_create_thread(&minmaxthread, (void (*)(void *))
mvc_minmaxmanager, NULL, MT_THR_DETACHED) != 0) {
+ if (MT_create_thread(&minmaxthread, (void (*)(void *))
mvc_minmaxmanager, NULL, MT_THR_JOINABLE) != 0) {
throw(SQL, "SQLinit", "Starting minmax manager failed");
}
#endif
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -154,6 +154,8 @@ void
mvc_logmanager(void)
{
Thread thr = THRnew("logmanager");
+
+ thr->waitfor = 1;
store_manager();
THRdel(thr);
}
@@ -162,6 +164,8 @@ void
mvc_minmaxmanager(void)
{
Thread thr = THRnew("minmaxmanager");
+
+ thr->waitfor = 1;
minmax_manager();
THRdel(thr);
}
diff --git a/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
b/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
--- a/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
+++ b/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
@@ -48,7 +48,7 @@ Operation successful
+--------------------------------------------------------------------------------------------------+
| mal |
+==================================================================================================+
-| function user.s4_1():void;
|
+| function user.s3_1():void;
|
| X_41:void := querylog.define("explain select count(*) from
tables\n;","sequential_pipe",27); |
| X_2:bat[:wrd] := bat.new(nil:oid,nil:wrd);
|
| X_1 := sql.mvc();
|
@@ -74,7 +74,7 @@ Operation successful
| X_33 := bat.append(X_27,X_32,true);
|
| X_34:wrd := aggr.sum(X_33);
|
| sql.resultSet(".L3","L3","wrd",64,0,7,X_34);
|
-| end user.s4_1;
|
+| end user.s3_1;
|
+--------------------------------------------------------------------------------------------------+
27 rows
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list