Move variable declarations out of the THREAD_BEGIN/THREAD_END macros and
documented them.