TH error handlers: Take a context-providing data variable

This allows us to get rid of the hacky globalL global variable.
Make all global variables live in thread-local storage

We use the gcc extension __thread to specify the TLS storage class.
THRandomState: New struct container with all the RNG parameters
TorchCFlags.cmake: Add a test for __thread presence
Merge pull request #154 from koraykv/thread-local

Thread local