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

How can you tell when a bitmap is ready to be read from? #251

Open
ghost opened this issue May 21, 2020 · 1 comment
Open

How can you tell when a bitmap is ready to be read from? #251

ghost opened this issue May 21, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented May 21, 2020

Hi!

I've noticed that this:

`func calculateBitSetChecksum(dest *checksumStruct, bitmap map[string]uint, imageAsBaseSixtyFour string, numberOfPixels int) {

for i := 0; i < len(imageAsBaseSixtyFour)-numberOfPixels; i++ {
	dest.checksum.Add(uint32(bitmap[imageAsBaseSixtyFour[i:(i+numberOfPixels)]]))
}
dest.checksumReady = true

}`

This is run in a go routine, and later on I want to do some operation much later:

for checksumsSlice[i].checksumReady == false {}

(This waits until checksumReady == true)

checksumReady is true but highlowcontainer is nil...

Is there a way to ensure that the bitmap is valid?

Thanks!

@lemire
Copy link
Member

lemire commented May 21, 2020

As far as I can tell from your comment, you are using unsafe Go code, and the issue you are pointing out is not related to roaring. It is important to understand what it is not because checsumReady has been set to true that the previous code has been executed. But the Go compiler and the processor will reorder or run at the same time instructions. It is not related to roaring: the same might happen with any data structure whatsoever. Even if your code may appear to work in some instance, it would still be buggy, subject to "random failures". If you want to create a data structure in one goroutine and access it safely from another goroutine, you need a strategy like stateful goroutines from the Go tutorial. There may be other valid strategies as well.

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

1 participant