Introduce lock api for instances

To allow coordination for tasks liek rescheduling of instnaces
this change adds the API to aquire a lock for an instance and
release it.