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

Concurrent map read and map write #685

Open
inkeliz opened this issue Nov 18, 2019 · 1 comment
Open

Concurrent map read and map write #685

inkeliz opened this issue Nov 18, 2019 · 1 comment
Milestone

Comments

@inkeliz
Copy link
Contributor

inkeliz commented Nov 18, 2019

Golang is a language that have a good support for concurrency and multithreading. I'm testing some stuff, as always, but I'm hit at fatal error: concurrent map read and map write.

Seems that Engo isn't capable to support multi-thread by default. There's a lot of map without any mutex:

engo/common/render.go

Lines 277 to 281 in d2790d2

if _, ok := rs.ids[basic.ID()]; ok {
return
}
rs.ids[basic.ID()] = struct{}{}

engo/common/spritesheet.go

Lines 113 to 127 in d2790d2

s.cache[index] = Texture{
id: s.texture,
width: float32(cell.Width),
height: float32(cell.Height),
viewport: engo.AABB{
Min: engo.Point{
X: cell.Position.X / s.width,
Y: cell.Position.Y / s.height,
},
Max: engo.Point{
X: (cell.Position.X + float32(cell.Width)) / s.width,
Y: (cell.Position.Y + float32(cell.Height)) / s.height,
},
},
}

That error can be triggered with anything like:

for i := 0; i < 10; i++ {
    go func() {
        //...
        element.RenderSystem.Add(
    }()
}

...


I'm thinking about create a queued channel, intended to receive and then calls Engo.

There's any plan to support concurrency?

@Noofbiz
Copy link
Member

Noofbiz commented Nov 22, 2019

I think supporting concurrency in systems would be an amazing thing! There are a few issues that would need to be worked through, mostly that openGL calls MUST be done on the main thread, the operating system requires it. So the render system or any system that does drawing would have to be guaranteed somehow to run on the main thread.

@Noofbiz Noofbiz added this to the 1.1 milestone Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants