Make sure thread order is stable (issue #353)