Primitive locking implemented, program working for multiple threads