Hooks, concurrency, race conditions

Thanks you, @mawww, that sounds like system interrupts. Does that still mean that hook code needs to be re-entrant? I.e. can this sequence happen (including user hooks):

: hook1
...
::: hook2
...
::::: hook1

My problem is simple, I want to echo -to-file to a temporary file with a unique name, under /run, without calling sh. So I was thinking of using a global counter option:

echo -to-file ".../something_%val{session}_%opt{cnt}"
# use, add NormalIdle hook to remove, whatever
set -add global cnt 1

Then it occurred to me that I can’t protect that option from race conditions.