work around portability issue on FreeBSD, in which the key returned from
pthread_key_create can be 0.