Saturday, May 18, 2024
HomeGolangYour opinion regarded Go Race Detector - Getting Assist

Your opinion regarded Go Race Detector – Getting Assist


Hello of us! Just lately, I’ve began to write down code associated to token updates. One chunk of my code in Goroutine is setting the worth, and one other one is studying it. Clearly, I noticed race (the identical instance from the official docs), which was additionally detected by go run -race .. However I’m questioning, what’s the purpose? I imply, for instance, the previous token lives for 3 hours, and the brand new one seems after 1 hour, so is it crucial to repair this challenge? I’ve already utilized utilizing sync/atomic, however for me, it’s no sense. May you clarify this case to me?

Talking concerning the instance, it reveals the concurrent entry to a map. As go.dev states, maps are usually not save for concurrent utilization in any respect and it was the aware choice. In the event you determined to retailer your tokens in map sort, then the way in which to ensure save code execution is to wrap it with mutex, wait group or atomic. From the sensible standpoint, if you’re positive that there’ll by no means be a state of affairs when your program will concurrently learn from and write to your map, then in fact you possibly can go away it as it’s. Nevertheless it’s all the time priceless to foresee doable issues and repair them from the beginning. It provides you deeper understanding of the language and the way issues work beneath the floor.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments