Applied the same thread stack initialization fix as in commit 7cf0039. Cleaned up the preprocessor condition macros so the code is easier to read.