Fix resource leak when using a thread pool

This should fix #4.