Fixed issue #1281, thread shutdown now properly waiting for quit.