-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Go v1.24, any platform.
In the context of shutting down goroutines,
my idem package used to use multiple mutexes, one within each
struct object IdemCloseChan and Halter. For reference,
https://github.com/glycerine/idem/blob/master/halter.go
is the implementation.
However when using trees to coordinate shutdown between
a lead package and a sub-package, I encountered alot of
deadlock issues due to different lock acquisition orders.
Therefore I arrived at the simple, perhaps crude, but effective
remedy of using a single mutex in the idem package for
all locking. The synctest document's discussion of
why mutexes are ignored indicated that
the Go standard library commonly does the same
for caches.
However I realized today that the Go build process allows
multiple versions of the same package to be included
in the final binary. This would re-introduce the two lock
ordering problem which I am seeking to avoid in
some cases, and might even violate mutual exclusion in others.
The runtime has the luxury of knowing it is the only
instance of the runtime, but user packages have
no such guarantee; I believe.
Questions:
a) is there a way to mark a package, such that the build
will fail if it includes two different versions of the same package?
After searching, I could not find such a facility.
b) Failing that, is there a way that a package itself can detect
and remedy the situation at runtime? Maybe it could read through the lately
included package manifests by some reliable API? I am
a bit loathe to run strings
on the final binary and hope
the format of the BOM does not change or get compressed over time.
If either such exists, please point me towards it.
Conclusion: if (b) exists but is the only means available today,
please consider this a feature request for
an (a) mechanism, with the rationale fully laid out above.
To elaborate, build processes should be able to eagerly detect and fail builds
that will always crash themselves for safety at runtime anyway.
Thank you.