I've been looking into false sharing and other pitfalls of parallelism on multi-core systems.
http://en.wikipedia.org/wiki/False_sharing
It seems like our multi-core hardware isn't that well thought out yet. In particular, locks can cause false sharing. Even go channels are based on locks!
I would love to see some kind of annotation in golang for padding certain structs to cache-line boundaries. This value can be read from most processors, so it could be done in a cross-platform fashion. The gringo ring-channel library has to do its own padding to avoid false sharing.
https://github.com/textnode/gringo/blob/master/gringo.go
type Gringo struct {
padding1 [8]uint64
lastCommittedIndex uint64
padding2 [8]uint64
nextFreeIndex uint64
padding3 [8]uint64
readerIndex uint64
padding4 [8]uint64
contents [queueSize]Payload
padding5 [8]uint64
}
There was a similar technique for padding Java objects, but it now turns out that the JVM is smart enough to optimize the padding out!