Thread-safe exceptions

Fixes #35.

Note that this uses GNU's [thread-local storage extension](http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Thread_002dLocal.html).