I think that locking scheme is possible to implement using the existing cmd/go/internal/lockedfile API.
go build would obtain a read-lock on the file (os.O_CREATE|os.O_RDONLY) go clean would obtain a write-lock on the file (os.O_CREATE|os.O_WRONLY)
We don't currently rely on file-locking for the cache, but since this would only prevent a build / clean race perhaps it's not so bad.
I am not sure that @jayconrod's second option would work: I believe the problem is that the clean deletes files previously created by this build, which the build is still relying on.
@jayconrod's first option would work as long as go clean -cache is also blocked until go build is done. This makes it look a lot like a RW lock, as @bcmills notes. The only remaining danger is starvation of the clean. (That could actually happen in my particular, unusual case, since I am running many concurrent builds, but that's probably not worth designing around.)
The text was updated successfully, but these errors were encountered: