Executes the given function task while holding the monitor of the given object lock and returns the task's result