Current scope needs to be thread-safe for training
Current scope needs to be thread-safe for training

scope's API modifies its internal state. And scope's
API can be called from multiple threads during traing.
Hence, we need locks to protect the scope's internal
states.

We can optimize it in the future. But the current
solution is buggy.

test=develop

reyoung/Paddle,baidu/Paddle,baidu/Paddle,chengduoZH/Paddle,tensor-tang/Paddle,PaddlePaddle/Paddle,chengduoZH/Paddle,chengduoZH/Paddle,baidu/Paddle,PaddlePaddle/Paddle,chengduoZH/Paddle,PaddlePaddle/Paddle,luotao1/Paddle,luotao1/Paddle,luotao1/Paddle,tensor-tang/Paddle,tensor-tang/Paddle,tensor-tang/Paddle,chengduoZH/Paddle,PaddlePaddle/Paddle,luotao1/Paddle,reyoung/Paddle,luotao1/Paddle,baidu/Paddle,PaddlePaddle/Paddle,PaddlePaddle/Paddle,luotao1/Paddle,luotao1/Paddle,PaddlePaddle/Paddle,tensor-tang/Paddle,reyoung/Paddle,reyoung/Paddle,reyoung/Paddle,reyoung/Paddle,baidu/Paddle