boehm-gc and sigwait() ?
Bryce McKinlay
bryce@albatross.co.nz
Tue Nov 23 03:06:00 GMT 1999
I've been trying to get libgcj to exit more cleanly on Ctrl-C, by
blocking the master thread on sigwait() and calling exit() on SIGINT.
See patch below. This works well, except seem to cause a hang in
boehm-gc when a collection occurs.
Can anyone see a way around this problem?
regards
[ bryce ]
Index: prims.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/prims.cc,v
retrieving revision 1.13
diff -u -r1.13 prims.cc
--- prims.cc 1999/11/05 17:34:32 1.13
+++ prims.cc 1999/11/23 06:26:01
@@ -793,7 +793,8 @@
main_thread->start();
_Jv_ThreadWait ();
- java::lang::Runtime::getRuntime ()->exit (0);
+ // _Jv_ThreadWait returns only on SIGINT (Ctrl-C).
+ ::exit(1);
}
void
Index: posix-threads.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/posix-threads.cc,v
retrieving revision 1.13
diff -u -r1.13 posix-threads.cc
--- posix-threads.cc 1999/11/04 16:45:11 1.13
+++ posix-threads.cc 1999/11/23 06:26:01
@@ -32,6 +32,7 @@
#include <jvm.h>
#include <java/lang/Thread.h>
#include <java/lang/System.h>
+#include <java/lang/Runtime.h>
// This is used to implement thread startup.
struct starter
@@ -53,7 +54,6 @@
// We keep a count of all non-daemon threads which are running. When
// this reaches zero, _Jv_ThreadWait returns.
static pthread_mutex_t daemon_mutex;
-static pthread_cond_t daemon_cond;
static int non_daemon_count;
// The signal to use when interrupting a thread.
@@ -260,7 +260,6 @@
pthread_key_create (&_Jv_ThreadKey, NULL);
pthread_key_create (&_Jv_ThreadDataKey, NULL);
pthread_mutex_init (&daemon_mutex, NULL);
- pthread_cond_init (&daemon_cond, 0);
non_daemon_count = 0;
// Arrange for the interrupt signal to interrupt system calls.
@@ -270,8 +269,7 @@
act.sa_flags = 0;
sigaction (INTR, &act, NULL);
- // Arrange for SIGINT to be blocked to all threads. It is only
- // deliverable to the master thread.
+ // Arrange for SIGINT to be blocked to all threads.
sigset_t mask;
sigemptyset (&mask);
sigaddset (&mask, SIGINT);
@@ -320,7 +318,7 @@
pthread_mutex_lock (&daemon_mutex);
--non_daemon_count;
if (! non_daemon_count)
- pthread_cond_signal (&daemon_cond);
+ java::lang::Runtime::getRuntime ()->exit (0);
pthread_mutex_unlock (&daemon_mutex);
}
@@ -366,16 +364,13 @@
void
_Jv_ThreadWait (void)
{
- // Arrange for SIGINT to be delivered to the master thread.
+ // block the thread, and only return if a SIGINT occurs.
sigset_t mask;
sigemptyset (&mask);
sigaddset (&mask, SIGINT);
- pthread_sigmask (SIG_UNBLOCK, &mask, NULL);
+ int count;
- pthread_mutex_lock (&daemon_mutex);
- if (non_daemon_count)
- pthread_cond_wait (&daemon_cond, &daemon_mutex);
- pthread_mutex_unlock (&daemon_mutex);
+ sigwait(&mask, &count);
}
void
More information about the Java
mailing list