August 27th, 2015, 4:55 pm
QuoteOriginally posted by: PolterFutures make sense when you need to easily communicate the results / synchronize operations (which includes expressing a possible dependency among these) between different threads (in particular, futures created using std::async can be used for returning results, where "returning" in a special case of "communication").If you just want to launch a function, you may as well use threads, but that's a different use case.And you can still communicate the results using threads, but it's less convenient and more error-prone (right tool - right job, and all that).In short, from Bjarne's "Tour":Quote13.7 Communicating TasksThe standard library provides a few facilities to allow programmers to operate at the conceptuallevel of tasks (work to potentially be done concurrently) rather than directly at the lower level ofthreads and locks:[1] future and promise for returning a value from a task spawned on a separate thread[2] packaged_task to help launch tasks and connect up the mechanisms for returning a result[3] async() for launching of a task in a manner very similar to calling a function.These facilities are found in <future> PPL has quantified many of these rules-of-thumbs as parallel design patterns.
Last edited by
Cuchulainn on August 26th, 2015, 10:00 pm, edited 1 time in total.