Lock the OS thread when acessing errors

The library stores error information in thread-local storage, which
means we need to make sure that the Go runtime doesn't switch OS
threads between the time we call a function and th time we attempt to
retrieve the error information.

@vmg this is what I was talking about in the other PR. It's either this or wrap every single function with our own C wrapper that copies the error.