Backport thread-local variables from Ruby 2.0

added `Thread#thread_variable_(get|set)`, `Thread#thread_variable?`, and
`Thread#thread_variables` for operating on variables that are local to
threads.

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=37384

https://github.com/rails/rails/issues/7746#issuecomment-9877533