Implemented thread synchronization