Fix for issue 11981
Switch to using pthread_key_t for Thread reference on Posix
pthread_key_delete(); Don't use pthread_key_t on OSX
missing else
Merge pull request #718 from radcapricorn/issue_11981

Fix for issue 11981 - deadlock during thread initialization on Posix