PATCH: Threads and SIGINT

Bryce McKinlay
Wed Dec 22 22:32:00 GMT 1999

Here's a new patch for threads and SIGINT handling. This is a somewhat refined
version of the threads patch that I have previously posted.

Basically it:

  - fixes miscellaneous bugs related to join() and interrupt().
  - allows interrupt() to interrupt threads that are in wait(), on Linux, using
the interrupt signal. This technique is unfortunately non portable (doesn't work
on Solaris) so there's a few #ifdefs in there. But it allows us to pass all the
threads stress tests I've come across so far.
  - fixes libgcj to exit cleanly and correctly on ^C by removing explicit SIGINT
handling and fixing an associated deadlock in boehm-gc.

I have tested these fairly extensively.

I'm going to be away for a week or two over Christmas/New Year and I'd really
like to get this stuff checked in before I go. Tom: can you look at this ASAP,

Regarding the Solaris thread problems reported by Joerg Brunsmann: I have
reproduced this on my Solaris x86 installation, and I'm convinced that these
problems are in fact due to a bug in Solaris rather than anything wrong with our
code. Solaris 7 (and I presume some 2.6 installations as well, since Joerg
reports that he is using 2.6) have a broken recursive mutex implementation,
resulting in calls to pthread_cond_wait never returning because it cannot
reacquire the mutex.

More information about the Solaris bug here:

 "There is an (escalated) Solaris 7 bug report about this problem:

   Bugid: 4288299
   Category: library
   Subcategory: libthread
   Synopsis: Recursive mutexes are not properly released

 The bug report discusses the deadlock problem with
 PTHREAD_MUTEX_RECURSIVE, but the same problem exists with

In order to fix this I think we need to force the use of default, non-recursive
mutexes on Solaris. I think this could be done with something like "#if defined
the top of posix-threads.h, but perhaps there is a better way.

1999-12-22  Bryce McKinlay  <>

        * java/lang/ (notify): Throw message with
        (notifyAll): Ditto.
        (wait): Ditto.
        * java/lang/ (isInterrupted): Don't clear interrupt_flag.
        (isInterrupted_): New function, which does clear interrupt_flag.
        (interrupt): Use `isInterrupted_'.
        * java/lang/ (interrupt): Don't call _Jv_CondNotify on
        (join): Set `prev' in joiner loop.
        Change various calls to `isInterrupted' to use `isInterrupted_'.
        * (_Jv_CondWait): Allways use pthread_cond_timedwait
        on linux. Set result to 0 on an interrupt. Test interrupted status
        of jthread object directly.
        FLAG_INTERRUPTED: removed.
        (_Jv_ThreadStart): Throw OutOfMemoryError if pthread_create fails.
        (_Jv_ThreadInterrupt): Don't set FLAG_INTERRUPTED.
        (_Jv_InitThreads): Don't block SIGINT.
        (_Jv_ThreadWait): Don't configure SIGINT handler.
        (_Jv_ThreadInitData): Set `jthread'.
        * include/posix-threads.h (_Jv_Thread_t): jthread: new field.

1999-12-22  Bryce McKinlay  <>

        * linux_threads.c: Don't block SIGINT, SIGQUIT, SIGTERM in the
        NO_SIGNALS case.

More information about the Java-patches mailing list