implements thread control