Locking for function calls and queuing on lock