making torch thread-safe, part of the patch inspired by @pesky
properly initializing pthread keys and adding a destructor
using THRandom_randomWithState in TensorMath.lua
Adding thread-safe patches