template
lock and unlock functions