I once played a bit with thread-safe collections I wrote using Java. With the number of threads increasing throughput did not just decline a bit, it completely plummeted that I was baffled.
Class ConcurrentHashMap, which is part of Java since JDK 1.5 is divided in segments. Segments help greatly in improving throughput. Have a look at https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/java/util/concurrent/ConcurrentHashMap.java. If you follow the places in the code where the inner class Segment is used, you will see how it works. Locking the entire map should only done if there is absolutely no way to avoid it like in something like this: myThreadSafeMap.lock(); Key key = myThreadSafeMap.get("foo"); if(key != null) { myThreadSafeMap.put("bar", "tomato"); } myThreadSafeMap.unlock(); If possible change to a design that avoids code like in the snippet above. Am Freitag, 16. Juni 2017 07:26:04 UTC+2 schrieb am...@ammar.io: > > https://github.com/ammario/mapgen > > > Features: > > - Supports any key/value pair supported by Go's native maps > - Allows complex operations via Lock() and Unlock() > - Generated code conforms to golint and gofmt > - Allows custom types > - Sensible default file name and map name > > -- 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.