Fixed thread synchronization bug.