not race condition. The hook routine of RtlAllocateHeap just indirectly calls RtlAllocateHeap itself, so the endless recursive call occurs and leads to stack overflow.
call chain((actually a loop):
RtlAllocateHeap -> RtlAllocateHeap hook routine ->enabled ->gettls -> TlsSetValue -> VirtualUnlock -> RtlAllocateHeap
call chain((actually a loop):
RtlAllocateHeap -> RtlAllocateHeap hook routine ->enabled ->gettls -> TlsSetValue -> VirtualUnlock -> RtlAllocateHeap