Automatically Locking a Thread