Use the lock decorator and close/join the thread pool

When the thread pool is owned by the engine (when it
is not passed in) we should be careful and ensure that
we close the pool (this stops it from accepting new
work) and then join on the pool (this ensures that all
contained threads complete) to avoid resource leakage.

Change-Id: Icb6e0f8051c017458657b4ff8872d3af44565c18
Fixes: bug 1221382