added thread function and lock code generator