On Mon, May 19, 2014 at 1:39 PM, <
jonathan....@gmail.com> wrote:
> Thanks so much for responding. I very much appreciate having a Go
> contributor give feedback. I have read through the Go memory model documents
> a number of times along with Google Code issues related to the memory model.
> Right now, the kinds of strong guarantees and capabilities that I'm
> accustomed to in other languages and runtimes simply aren't found in Go, so
> there is a certain amount of "programming by coincidence" that I am working
> through.
Don't program by coincidence. The Go memory model is clear: if you
need to share memory, you also need explicit synchronization.
I read somewhere that one of the reasons that the Itanium architecture
wasn't successful was that compilers had to insert lots of memory
barriers to enforce C++'s stronger guarantees than the hardware had,
which obviously killed actual vs theoretical performance.
> That being said, the particulars of the scenario you mentioned may have a
> simple solution. For example, by providing a simple function that reads the
> cursor value at startup (or some other time) such that it doesn't affect
> runtime performance and it indicates to the compiler that the value will be
> read and considered such that it should not be optimized away.
Even if the value is read once (at startup), the compiler can stil
optimize away writes as no-ops. See the "an aggressive compiler might
delete the entire go statement" line in
http://golang.org/ref/mem
> I sincerely appreciate your insights into these potential pitfalls as I move
> forward with this project. My plan have a full set of unit and integration
> tests that assert the behavior of the entire library against multiple
> versions of the Go runtime on different operation systems and CPU
> architectures. Such a suite of tests should help to mitigate any obvious
> issues as the Go runtime matures and further internal optimizations occur.
You might catch obvious issues with existing compilers, but the Go
memory model says that you still will have non-obvious issues, and
they are the hardest ones to debug.