thread implementation version 0.1 some parts copied from gcc source code.