-
I am currently looking at the examples, videos and trying to understand how AsyncComputeTaskPool works. I am getting the error '1 must outlive lifetime 'static when I try to use anything I previously used in my system ( query, commands, etc.. ) According to this video, anything to be used in an AsyncComputeTaskPool needs to be copied.. https://www.youtube.com/watch?v=QTUEyAZmdv4 Is that the only way to have computations in the background? If so I feel like this wastes an enormous waste of runtime.. I have a global object based on which I want to generate a mesh, which is a really expensive operation, but what is more expensive is copying the whole thing every time a new mesh needs to be created. I find that practice wasteful.. is there any other way to run a computation in the background or is copying the only way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It depends on two factors:
If the answer to (2) is "yes". Then the rust type system actually saved you from hitting nasty bugs! You should consider an alternative design. It's because you can't predict what happens first when two different threads try to access the same data, and it is likely that you would get two different results when running the software two different times, for the same code… This is called a race condition. So assuming you don't mutate the global object under the feet of the generation process, you have a few options:
Some people might recommend using a lock such as If you use locks, consider using many locks with fine-grained access, otherwise you risk just forcing your whole game to be single threaded. |
Beta Was this translation helpful? Give feedback.
It depends on two factors:
If the answer to (2) is "yes". Then the rust type system actually saved you from hitting nasty bugs! You should consider an alternative design. It's because you can't predict what happens first when two different threads try to access the same data, and it is likely that you would get two different results when running the software two different times, for the same code… This is called a race condition.
So assuming you don't mutate…