Replace thread local global by struct on the stack