Hacker News new | past | comments | ask | show | jobs | submit login

What do you mean by reusable exactly? And how does proactive computing differ? Do you have an example you can share?



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.


What would be the purpose of yielding control from the thread and tell it to wait, rather than just let it run to completion?


Sometimes you don't know where you want to spend your CPU budget until you have more information.


Maybe I misunderstand you, but telling the thread to halt is surely a waste of those resources?


Because 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




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: