The macro IMPLEMENT_RANDOMIZE_STACK uses a "static char" to store the number of loops. This is shared between threads (it is used in at least 9 different thread functions) and operations such as '--' are not guaranteed to be atomic. If multiple threads end up in this loop at the same time, there could be executions that would result in an infinite loop (or at least, unreasonably deep stacks that exceed the hardcoded limit of 20).
To fix this we could use thread-local storage here (__thread /__declspec(thread) depending on the compiler...). Or find an alternative for this... slightly crazy macro.