Properly initialize the stack with emulated thread variables.
Remove references to pthread_mutex_timedlock().

The pthread_mutex_timedlock() function is not supported on a number
of architectures and is not actually used by the library or compiler,
but prevents C++ compilation on systems that do not support it when
threads are enabled.
Merge pull request #1636 from rbehrends/fix-thread-issues

Fix some thread issues