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

Correct use of Garbage collection #40

Open
biddisco opened this issue Feb 11, 2019 · 2 comments
Open

Correct use of Garbage collection #40

biddisco opened this issue Feb 11, 2019 · 2 comments

Comments

@biddisco
Copy link

In the blog/docs it says

To make QSBR work, each thread must periodically call junction::DefaultQSBR.update at a moment when that thread is quiescent – that is, not in the middle of an operation that uses the map. In a game engine, you could call it between iterations of the main loop.

I am experimenting with the leapfrog map, and inserted a call to junction::DefaultQSBR.flush() (since there is no update()). However, when I add the flush call, my code throws exceptions due to empty states in some objects retrieved from the map. There is no single place in the code where I can guarantee that the map is not accessed since everything is completely asynchronous. When one thread is calling flush() another thread might decide to insert or remove something from the map.

Is there a recommended way of dealing with this? (Also please clarify "each thread must periodically call" - do you mean that all threads must call it individually, or can any one single thread call it from time to time).

@preshing
Copy link
Owner

Hi,

What makes you say there is no update()? It's right here...!

junction::DefaultQSBR.flush() is not the right function to call during normal use. You really need junction::DefaultQSBR.update(). (flush() only exists in case you want to delete all Junction maps and shut down the whole QSBR subsystem, but still keep your app running.)

do you mean that all threads must call it individually, or can any one single thread call it from time to time

Each thread must call update() individually, and each thread must pass its own QSBR::Context to the call. You basically just create one QSBR::Context per thread (if that thread will use a Junction map). You can create the QSBR::Context on the stack.

This inconvenience is admittedly the main drawback to using Junction maps.

@biddisco
Copy link
Author

Oops. Sorry, I didn't realize I needed a context per thread and I grepped for update with no arguments and missed it.
I will fix my test and close this issue if I have no further problems. Thanks

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