[PATCH] LLD: Implement our own future and use that for FileArchive::preload().

Chandler Carruth chandlerc at google.com
Mon Mar 2 20:31:17 PST 2015


On Mon, Mar 2, 2015 at 8:20 PM, Rui Ueyama <ruiu at google.com> wrote:

> Oh, and speaking of the API, I don't actually understand why C++11
> separates producer side (std::promise) and consumer side (std::future). My
> implementation is not compatible with that at all -- I just defined
> std::future and use that for both, just like future in
> java.util.concurrent. Seems working fine -- so I didn't go so far as to
> define one more class.


The reason why the C++ APIs are in different classes is to make the
interfaces harder to use incorrectly.

By giving the producer thread only the interface which it is allowed to
use, and the consumer thread only the interface which it is allowed to use,
using the wrong interface or doing something that would otherwise hit an
assert or cause a race condition now is a compile-time error.

It certainly adds a layer of complexity to the entire thing, but the belief
was that it would significantly improve the usability of the API, and I
think I largely agree with that.

If producers are always modeled as closures (the way they generally are in
Java) then this isn't such a big deal as there essentially is no producer
API to speak of, and you can just deal in the future side of the API.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150302/c4a38eee/attachment.html>


More information about the llvm-commits mailing list