Changeset: a61ae7e30676 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a61ae7e30676
Modified Files:
gdk/gdk_system.c
gdk/gdk_system.h
monetdb5/extras/pyapi/pyapi.c
Branch: pyapi
Log Message:
To prevent deadlocks in forked processes set # of threads to 1 and ignore locks
and semaphores.
diffs (101 lines):
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -55,6 +55,8 @@
#include <unistd.h> /* for sysconf symbols */
+int forked_process = 0;
+
MT_Lock MT_system_lock MT_LOCK_INITIALIZER("MT_system_lock");
#if !defined(USE_PTHREAD_LOCKS) && !defined(NDEBUG)
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -126,14 +126,15 @@ typedef struct {
#define MT_lock_destroy(l) pthread_mutex_destroy(&(l)->lock)
#define MT_lock_set(l, n) \
do { \
- TEMDEBUG fprintf(stderr, "#%s: locking %s...\n", \
- (n), (l)->name); \
+ if (forked_process) break; \
+ TEMDEBUG fprintf(stderr, "#%s: locking %s...\n", (n),
(l)->name); \
pthread_mutex_lock(&(l)->lock); \
- TEMDEBUG fprintf(stderr, "#%s: locking %s complete\n", \
+ if (forked_process) fprintf(stderr, "#%s: locking %s
complete\n", \
(n), (l)->name); \
} while (0)
#define MT_lock_unset(l, n) \
do { \
+ if (forked_process) break; \
TEMDEBUG fprintf(stderr, "#%s: unlocking %s\n", \
(n), (l)->name); \
pthread_mutex_unlock(&(l)->lock); \
@@ -256,8 +257,11 @@ gdk_export ATOMIC_TYPE volatile GDKlocks
#endif
+extern int forked_process;
+
#define MT_lock_set(l, n) \
do { \
+ if (forked_process) break; \
_DBG_LOCK_COUNT_0(l, n); \
if (ATOMIC_TAS((l)->lock, dummy, n) != 0) { \
/* we didn't get the lock */ \
@@ -334,16 +338,16 @@ typedef struct {
#define MT_sema_destroy(s) pthread_sema_destroy(&(s)->sema)
#define MT_sema_up(s, n) \
do { \
- TEMDEBUG fprintf(stderr, "#%s: sema %s up\n", \
- (n), (s)->name); \
+ if (forked_process) break; \
+ TEMDEBUG fprintf(stderr, "#%s: sema %s up\n", (n), (s)->name);
\
pthread_sema_up(&(s)->sema); \
} while (0)
#define MT_sema_down(s, n) \
do { \
- TEMDEBUG fprintf(stderr, "#%s: sema %s down...\n", \
- (n), (s)->name); \
+ if (forked_process) break; \
+ TEMDEBUG fprintf(stderr, "#%s: sema %s down...\n",(n),
(s)->name); \
pthread_sema_down(&(s)->sema); \
- TEMDEBUG fprintf(stderr, "#%s: sema %s down complete\n", \
+ if (forked_process) fprintf(stderr, "#%s: sema %s down
complete\n", \
(n), (s)->name); \
} while (0)
diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -15,6 +15,7 @@
#include "sql_catalog.h"
#include "pyapi.h"
#include "connection.h"
+#include "mal_dataflow.h"
// Python library
#undef _GNU_SOURCE
@@ -555,6 +556,8 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
}
else if (pid == 0)
{
+ forked_process = 1;
+ GDKnr_threads = 1;
child_process = true;
#ifdef _PYAPI_TESTING_
if (!disable_testing && !option_disablemalloctracking &&
benchmark_output != NULL) { init_hook(); }
@@ -566,11 +569,11 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
//main process
int status;
bool success = true;
-
//wait for child processes
MT_lock_unset(&pyapiLock, "pyapi.evaluate");
waitpid(pid, &status, 0);
+
if (status != 0)
success = false;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list