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

Help with my configuration #9

Open
bjadamson opened this issue Sep 3, 2016 · 2 comments
Open

Help with my configuration #9

bjadamson opened this issue Sep 3, 2016 · 2 comments

Comments

@bjadamson
Copy link
Contributor

Hey,

I for some reason can't seem to get one of my systems to run in parallel. Could you take a look at my configuration? Basically one of my systems has all my opengl code in it, that system crashes if multiple threads try and run it.

I configured my system to run singlethreaded, or atleast I thought I did, but the evidence shows my "rendering system" is being executed by multiple threads. Any ideas?

proof (using gdb, system initially runs on thread #1, later segfaults on thread #4):
ss.png

configuration:
https://github.com/bjadamson/BoomHS/blob/ecst/include/game/boomhs/boomhs.hpp#L198-L206

example I copied:
https://github.com/SuperV1234/ecst/blob/948491e47e11327cff8f62a04fe02fda3c08bd6d/example/pres_code.cpp#L766

The actual system code is here, and maybe important. I only expect the whole "system" to be executed serially, because I disabled inner parallelism. Is that expectation correct?
https://github.com/bjadamson/BoomHS/blob/ecst/include/game/boomhs/boomhs.hpp#L43-L55
https://github.com/bjadamson/BoomHS/blob/ecst/include/game/boomhs/boomhs.hpp#L236

Thx !!

@vittorioromeo
Copy link
Owner

Your current configurations says:

  • s::render_triangle and s::io_system can run in parallel.
  • All entities subscribed to s::render_triangle will be processed in a single subtask (single-threaded).
  • All entities subscribed to s::io_system will be processed in a single subtask (single-threaded).

There is no guarantee that the single-threaded systems will be executed on the main thread - their single subtask will be sent to the thread pool as any other subtask. The guarantee is that the system won't be split in multiple subtasks. There is no guarantee that a particular system will be executed on the same thread multiple times (i.e. could run on thread 1 on first frame, on thread 4 on second frame).

Is this a possible cause of your issue?

@bjadamson
Copy link
Contributor Author

Ok, looks like you had some insight into the problem I didn't have yet. The exact crash is because sdl and opengl have expectations on the thread that created them being the same thread all future draw calls from, kind-of sort-of I mostly understand it, I think.

So, it seems like the obvious solution is to just not put this code into a system, and write it directly into the main loop around the call to step(...). Does this seem reasonable?

If so, follow up question. I'd like to iterate over the entities using the same syntax outside of a "system" (because of the reasoning right above) to iterate over my "red_triangle" components (be kind, I'm still just trying to integrate the library with opengl/sdl). Is this possible? So far the only API's I can find for iterating over the entities looks like this:
https://github.com/SuperV1234/ecst/blob/master/example/particles.cpp#L444-L451

Is there an API for iterating over components/entities outside of the context of one of these proxy.execute_systems() ... functions?

Either that, or do you think it would be more straight forward to "pin" the task somehow to a thread? I guess I could look into implementing this if you think that's smart. It does feel like it goes against the spirit of the library (parallel everything), but I'm unsure how to use opengl/sdl with the library without further inquiry.

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

2 participants