It's generally a bad idea to remove items from a container while iterating through it. And fix the thread safe issue.
Merge pull request #727 from kejinlu/master

It's generally a bad idea to remove items from a container while iterating through it.