Fixes race condition when callback is invoked from thread pool

Fixes issue #153