Managed thread id fix for 5.0

Graft of the 'managed thread ID fix' to unity-staging branch for 5.0. 

ACompleteBuild on Katana is green (#337).