I'm busy with a project that requires a map accessed by multiple
go-routines. Since maps aren't thread-safe, I implement my own locks.
I've come up with 3 variations:
1. A goroutine handles the map, with a _get_ and a _set_ channel.
2. A goroutine handles the map with a single channel, then type-checks to
decide whether the request is a _get_ or a _set_.
3. Use _sync.RWLock_ to coordinate map access. No goroutines.
I've implemented all three, along with some performance testing:
Here's the thing: using sync is about twice as fast as using a goroutine.
An example output:
In parallel on 8 CPUs with 10 goroutines
So my questions:
1. Can anyone see any obvious problems with my code? Have I made a mistake?
2. Is there a better way?
3. If there's no better way, is this just a situation where goroutines are
not the best solution?
All the best,
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 email@example.com.
For more options, visit https://groups.google.com/groups/opt_out.