4 ms·
In the go source there is the use of tryAcquireSema which is similar to TryLock in src/net/dnsclient.go: // tryUpdate tries to update conf with the named r
by benmmurphy 4y ago
In the go source there is the use of tryAcquireSema which is similar to TryLock in src/net/dnsclient.go:
// tryUpdate tries to update conf with the named resolv.conf file.
// The name variable only exists for testing. It is otherwise always
// "/etc/resolv.conf".
func (conf *resolverConfig) tryUpdate(name string) {
conf.initOnce.Do(conf.init)
// Ensure only one update at a time checks resolv.conf.
if !conf.tryAcquireSema() {
return
}
defer conf.releaseSema()
I think this has the same behaviour except it is implemented using channels. It is used because go wants to make sure changes to /etc/resolv.conf are eventually taken into account when making DNS lookups but they don't want to check the file on every DNS lookup.