fix a critical secton bug