The trick was to initialize everything within the thread, not in the
main thread.