Move Non Send Resources into thread locals#5135
Move Non Send Resources into thread locals#5135hymm wants to merge 6 commits intobevyengine:mainfrom
Conversation
82da848 to
247f2b1
Compare
|
We're already using |
|
This appears to be complementary to #3519, correct? |
This works very differently despite the similar name. Quoting from the crate:
There is also the issue that
Yeah. I'll add it to the description |
fb5f1ef to
0d9c5e8
Compare
0d9c5e8 to
d366917
Compare
Objective
Fix problem with world being send and dropping non send resources on the wrong thread.
Alternative to #3519,
Solution
thread_local_objectcrate to move non send resources into thread local memory. This means that trying to access the non send resource off the thread that spawned it will end up with the resource not being found.thread_local_objectdrops the objects it keeps when the thread is dropped instead of when it's instance is dropped.Advantages
Disadvantages
world.remove_non_send_resourcevs removing the resource from the ThreadLocalResource,ThreadLocalResouce::remove.thread_local_objectare not dropped when theThreadLocalResourceis dropped. They are only dropped when the thread is dropped orThreadLocalResource;:removeis called on the corrent thread. I added an explicit drop for the thread thatThreadLocalResourceis dropped on, but this doesn't help if the world has been sent. So this is a potential memory leak.Migration Guide
// TODO
ToDo