Add thread synchronization