Lock when setting the timeout function