I have a Swift class which uses a traditional Cocoa singleton pattern: one static shared
constant and a private init
that is only called once for that shared constant. It's like this:
public class Foo {
public static let shared = Foo()
private init() { /* ... */ }
public func bar() { /* ... */ }
public func baz() { /* ... */ }
}
// Meanwhile, in multiple places upon multiple threads:
Foo.shared.bar()
Foo.shared.baz()
If I have a dozen threads calling functions on that constant, does it pause all calls until that initializer completes, or should I have some protections within those instance functions to wait for initialization to complete?