added basic locking logic, gentle sigint handling in example