0

I need to use a very big hash-table, and access it from many readers and many writers in parallel. is there data structure like map, that support many reads and writes in parallel, without locking the whole structure each access?

2 Answers 2

1

Since you asked for a map

without locking the whole structure each access

I direct you to the following implementation:

https://github.com/cornelk/hashmap

This project implements a pure lock free hash map data structure using atomic instructions common in many CPU architectures

The regular go sync.Map still uses an underlying Mutex which locks the corresponding map datastructure.

Sign up to request clarification or add additional context in comments.

Comments

0

Package sync provides the concurrent safe map.

Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.


Although the spec itself point out these two specific cases when it should be used(otherwise they suggest using the normal map with locking mechanism):

  1. when the entry for a given key is only ever written once but read many times, as in caches that only grow
  2. when multiple goroutines read, write and overwrite entries for disjoint sets of keys

1 Comment

thanks for the answer. in my case both of this conditions are not exists

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.