use dynamic vars to emulate a thread local mutable stack