Added functions lock_cast, which provide a cast locked pointer