multithreading - async's future holds on to copies of arguments after async task completes -


consider scope

{   std::shared_ptr<t> data = new t();   std::future f = std::async(std::launch::async, operation, data);   keep_for_later(std::move(f)); } 

where keep_for_later() stores future in shoebox while, while operation() completes quickly.

i seeing object of type t not destroyed upon operation()'s return, rather kept alive arbitrarily long time, long future returned async() call not destroyed.

obviously, async() must copy parameters, , hold these copies alive until asynchronously invoked function returns. seems suboptimal me these copies not destroyed function done, temporary arguments destroyed in normal synchronous function call (if called operation(std::shared_ptr<t>(data)) instead of through async(), temporary object created lifetime of call). dealing sloppy implementation?

is there c++11 portable way prevent association of lifetime of temporary copies returned future?

if (as suspect) there none, there alternative std::async()-like implementation allow (e. g. in boost), can use portably both microsoft cl , gcc?

'data' still alive within function scope.... so, while async running, there @ least 2 copies.... if want prevent that, move 'data' async

{     std::shared_ptr<t> data = new t();     std::future f = std::async(std::launch::async, operation, std::move(data));    keep_for_later(std::move(f)); 

}


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -