Page MenuHomePhabricator

Make ThreadPool support running tasks that return values

Authored by zturner on Jun 12 2018, 9:00 PM.



previously ThreadPool could only execute tasks that did something, not tasks that returned values. We can improve this with a little bit of type erasure. The idea is that instead of queueing up packaged_task<void()>'s, we queue up unique_ptr<TaskBase>, where TaskBase is a base class that has an pure virtual execute() method. A templated derived class stores an appropriately typed package_task<T()>, which is run with execute() is called.

Diff Detail


Event Timeline

zturner created this revision.Jun 12 2018, 9:00 PM
davide accepted this revision.Jun 12 2018, 10:46 PM

Looks fine to me. Do you plan to use It in a subsequent patch?

This revision is now accepted and ready to land.Jun 12 2018, 10:46 PM
labath accepted this revision.Jun 13 2018, 12:31 AM

looks good

30 ↗(On Diff #151097)

you could include cassert so it fits in nicely with the other c++ headers.

55–56 ↗(On Diff #151097)

Are these still needed/used ?

Looks fine to me. Do you plan to use It in a subsequent patch?

Yes, maybe not immediately, but it's one more step along the way of things I find I'm needing.

This revision was automatically updated to reflect the committed changes.