Base code for multithread programms