Minor edit. Generate random thread id when missing.
Remove debug.
Flush caches appropriately to successfully switch contexts.