Received: from SOUTH-STATION-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA16023; Fri, 1 Dec 95 09:02:53 EST
Received: from DUNCAN.CS.UTK.EDU by MIT.EDU with SMTP
	id AA01926; Fri, 1 Dec 95 09:00:46 EST
Received:  by duncan.cs.utk.edu (cf v2.11c-UTK)
          id JAA25378; Fri, 1 Dec 1995 09:01:50 -0500
Date: Fri, 1 Dec 1995 09:01:50 -0500
From: cabbott@cs.utk.edu
Message-Id: <199512011401.JAA25378@duncan.cs.utk.edu>
To: pthreads-bugs@MIT.EDU
Subject: malloc() and dead threads

I've encountered a problem when a thread receives a signal while
doing a malloc(), AND dead threads exist.   This is what happens:
 
        - malloc/free mutex becomes locked during malloc()
 
        - signal occurs
 
        - pthread_kernel_lock is incremented to 1 within sig_handler_real()
 
        - free() is called within context_switch() to remove dead threads
 
        - free() tries to obtain the malloc/free mutex lock.
 
        - pthread_kernel_lock is incremented to 2 within pthread_mutex_lock()
 
        - the malloc/free mutex lock cannot be obtained since it was
          already locked during the previous call to malloc().
 
        - pthread_resched_resume() is called with a state of PS_MUTEX_WAIT
          since the lock was already in use.
 
        - sig_handler() is called within pthread_resched_resume.
 
        - The first 2 statements of sig_handler() are:
 
                if(pthread_kernel_lock != 1) {
                        PANIC();
                }
 
        - Since pthread_kernel_lock is 2, the program aborts.

Please send me an acknowledgement when you've received this.  Thank you.

Cathy Abbott
cabbott@cs.utk.edu
