You're not wrong, that code isn't a safe use of a package-level variable. On Tuesday, 8 November 2016 20:16:28 UTC, krolaw wrote: > > Hopefully someone can explain where my understanding of dataraces is wrong. > > As an example, I'd like to use the appengine cloudstorage example: > > https://cloud.google.com/appengine/docs/go/googlecloudstorageclient/app-engine-cloud-storage-sample#specifying_the_cloud_storage_bucket > > When a web request comes in, it checks if the bucketname is empty. If it > is, it sets the bucketname using the result from > file.DefaultBucketName(ctx). It all seems like a good idea, but I'm > confused because the bucket name variable is accessed by multiple > goroutines. What if on startup, two requests come in at roughly the same > time? Would we possibly have two goroutines reading and writing to the > same variable? Does the appengine guarantee that the first request > finishes before any other starts? Or is this somehow a minor unimportant > datarace, as it is unlikely to occur and even if it does, > file.DefaultBucketName returns the same value... so it doesn't matter that > it gets called twice and sets the bucket name twice? > > Thanks and apologies for my confusion. > >
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.