4 ms·
Reusable as in, I can create a datastructure in a thread, do some computation, yield control from the thread (wait for something else to tell it to go again), t
by opportune 7y ago
Reusable as in, I can create a datastructure in a thread, do some computation, yield control from the thread (wait for something else to tell it to go again), then come back to the thread with the same datastructure and keep going. With Tasks, you are supposed to let tasks complete rather than let them pause/sync so anything you declare locally is lost when you want to restart it. The workaround is to declare things in a higher scope and pass them into tasks as they are reran - this makes tasks not suited to things where you want to persist data, since tasks are opinionated in that they are only meant to contain logic, not state, so you have to add your own external logic to manage the allocation of state to the tasks that you keep recreating
This trait of tasks makes sense when writing things like web servers because it prevents developers from shooting themselves in the foot by writing something that isn't stateless.
By proactive computing, I mean some program that always has control of the entire execution graph. For example, a simulation may initialize a bunch of datastructures, separate some of them into threads, run the threads, wait for all of them to complete x ticks, do some synchronization or measurement of the total system, then continue y times, and exit.
- DNF2 7y agoWhat would be the purpose of yielding control from the thread and tell it to wait, rather than just let it run to completion?
- ska 7y agoSometimes you don't know where you want to spend your CPU budget until you have more information.
- DNF2 7y agoMaybe I misunderstand you, but telling the thread to halt is surely a waste of those resources?
- opportune 7y agoBecause sometimes you need to sync the entire program state, or some subset of the state, to make measurements or to let disparate parts of the system interact