Use API call instead of accessing a global variable for receiving the current thread.