Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fatal error: concurrent map writes #29

Closed
4n70w4 opened this issue Apr 8, 2020 · 2 comments
Closed

fatal error: concurrent map writes #29

4n70w4 opened this issue Apr 8, 2020 · 2 comments

Comments

@4n70w4
Copy link

4n70w4 commented Apr 8, 2020

var Counter *hyperloglog.Sketch

...

Counter = hyperloglog.New16()

...

		bpk := make([]byte, 8)
		binary.LittleEndian.PutUint64(bpk, pk)
		Counter.Insert(bpk)
fatal error: concurrent map writes

goroutine 458 [running]:
runtime.throw(0x788fc0, 0x15)
	/Go/src/runtime/panic.go:1114 +0x79 fp=0xc005f75e48 sp=0xc005f75e18 pc=0x435c49
runtime.mapassign_fast32(0x742f00, 0xc00813aba0, 0xc002276860, 0xa52e40)
	/Go/src/runtime/map_fast32.go:101 +0x328 fp=0xc005f75e88 sp=0xc005f75e48 pc=0x411028
github.com/axiomhq/hyperloglog.set.add(...)
	/Go/bin/src/github.com/axiomhq/hyperloglog/sparse.go:44
github.com/axiomhq/hyperloglog.(*Sketch).InsertHash(0xc0000615f0, 0x89da180ed69d24d0, 0x8)
	/Go/bin/src/github.com/axiomhq/hyperloglog/hyperloglog.go:220 +0x117 fp=0xc005f75ed0 sp=0xc005f75e88 pc=0x6d4797
github.com/axiomhq/hyperloglog.(*Sketch).Insert(0xc0000615f0, 0xc0020a7388, 0x8, 0x8, 0xc00848fa40)
	/Go/bin/src/github.com/axiomhq/hyperloglog/hyperloglog.go:214 +0x65 fp=0xc005f75f00 sp=0xc005f75ed0 pc=0x6d4665
main.BulkWorker(0x18ad287d)
	/src/BulkRequest.go:92 +0x1cb fp=0xc005f75f58 sp=0xc005f75f00 pc=0x6da52b
main.main.func1(0x70c3c0, 0xc00205eaa0)
	/src/api.go:71 +0x46 fp=0xc005f75f80 sp=0xc005f75f58 pc=0x6dccd6
github.com/panjf2000/ants.(*goWorkerWithFunc).run.func1(0xc005d43290)
	/Go/bin/src/github.com/panjf2000/ants/worker_func.go:68 +0xb7 fp=0xc005f75fd8 sp=0xc005f75f80 pc=0x6d9b07
runtime.goexit()
	/Go/src/runtime/asm_amd64.s:1373 +0x1 fp=0xc005f75fe0 sp=0xc005f75fd8 pc=0x4626f1
created by github.com/panjf2000/ants.(*goWorkerWithFunc).run
	/Go/bin/src/github.com/panjf2000/ants/worker_func.go:48 +0x53
@cupen
Copy link

cupen commented Sep 13, 2022

It works as expected.
You should use sync.Mutex or sync.Once if you want to initializing a singleton instance in multi-threaded.
https://pkg.go.dev/sync

@seiflotfy
Copy link
Member

Thank you @cupen 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants