Fix threads synchronization