Theoretically it can be called by multiple threads, creating multiple connections. Practically this will never happen since it is called once from main().
If we want to fix it we can use something like:
static pthread_once_t connect_once = PTHREAD_ONCE_INIT;
xpc_object_t vmnet_broker_start_session(const char *network_name, struct vmnet_broker_error *err) {
pthread_once(&connect_once, connect_to_broker);
...
}
Theoretically it can be called by multiple threads, creating multiple connections. Practically this will never happen since it is called once from main().
If we want to fix it we can use something like: