Return correct errors on terminating thread.

Fixes Final Fantasy 4 hangs when playing videos a second time.
Merge pull request #2184 from unknownbrackets/thread-funcs

Return correct errors on terminating thread