This way we can ensure DeclareAsHostThread and UndeclareAsHostThread are called when locking and unlocking.