Fix deadlock in multithreading

Fixes #5971.

Thought of putting it in native, but DoState... anyway, can't really do iterators without special iterator classes too, so not that generally useful after all.

-[Unknown]