added tracking the number of pthreads using a specific `thread_key`
this prevents a key to be deleted if it is still used by other pthreads