fix thread synchronisation