Updated thread.h

Several basic fixes