#11866: Eliminate race condition in the computation of names for new threads.

Original patch by Peter Saveliev.
#14201: Update ctypes docs to match behavior changed from 214b28d7a999.

Original patch by Erik Johansson, slightly updated by Meador Inge.