To avoid nonreentrancy when writing new software, avoid using global variables to store data that is thread-specific data.
Alternatively, allocate thread-specific data on the stack or heap and explicitly pass its address to called routines.