LocalThread generalized for Matlab support.