Introduce lock api for instances

To allow coordination for tasks liek rescheduling of instances this change adds the API to aquire a lock for an instance and release it.

/cc @bernerdschaefer @typingduck