[2.2] Fixes tests that left threads behind after run

introduced a simple tracking method that can be used for labelling
threads, only active if assertions are enabled.