On Tue Jul 9 19:03:25 2024 +0000, Brendan Shanks wrote:
I'm not sure how likely it is, but if the first thread has set mib_len but sysctlnametomib() hasn't returned yet, another thread would call sysctl() with an invalid/empty mib. Maybe use dispatch_once() or pthread_once() to fill the cache? Or don't cache at all?
Ah, good call. Breaking things out into a separate function for pthread_once would be verbose. What if I just stop having `mib_len` do double-duty and do something like this?
``` static int mib[CTL_MAXNAME], inited = 0; static size_t mib_len = CTL_MAXNAME; if (!inited) { sysctlnametomib( "net.inet.tcp.pcblist64", mib, &mib_len ); inited = 1; } ```
Then the worst case is an extra call to `sysctlnametomib`.