Reviewed!

Thanks,
David

On 21/08/2013 6:44 PM, Staffan Larsen wrote:
I still need a Reviewer to ok this.

Thanks,
/Staffan

On 19 aug 2013, at 11:08, Staffan Larsen <staffan.lar...@oracle.com> wrote:

We are using the mach thread port name as the os thread identifier on OS X. We get this 
value by calling mach_thread_self(), but we (I) didn't realize that this "port" 
resource is reference counted and mach_thread_self() increases the reference count, but 
we never call mach_port_deallocate() to decrease the reference count. This leads to a 
resource leak and eventually mach_thread_self() will return 0 to indicate that we are out 
of ports. Running out of ports causes the pthreads implementation (which is built on top 
of mach) to spin forever in some calls (most notably in this case pthread_kill()).

One way to fix this is to make sure we call mach_port_deallocate() for each 
call to mach_thread_self(). However, this adds extra complexity to the code and 
also makes it slower. Another solution is to ask pthreads for the mach port 
name that it already has. Pthreads provides the function 
pthread_mach_thread_np() for this purpose. In this case there is no need to 
deallocate the port since pthread_mach_thread_np() will not increase the 
reference count (and pthreads will call deallocate on the port once the thread 
terminates).

This fix has been verified by seeing that the number of ports the process has 
allocated does not increase in Activity Monitor (or top). It has also passed 
JPRT testing on all platforms.

webrev: http://cr.openjdk.java.net/~sla/8022808/webrev.00/
(there is not publicly visible bug for this)

Thanks,
/Staffan

Reply via email to