synchronize cross-thread  access to @pending
refactor for performance and readability