Fix issue that can result in concurrent invocation of exit callback

from work queue by calling the exit callback with the work queue
mutex held. Added corresponding unit test.