The correct way would be to use a trailing closure.
Something like
func fizzle() {
lock_guard(mutex) {
if (count_ >= 3) {return; }
count_ = count_ + 1;
}
}
Where lock_guard() might be then something like this, implemented on some utility library: func lock_guard (_ m:Mutex, action: () -> Void) -> Void {
m.lock();
defer {
m.unlock();
}
action();
}
This is one of the RAII approaches in functional programming, using partial function application and higher order functions, to create new types of operations.