C++ 中,std::future 和 std::promise 名字的來歷?

C++ 11 標準添加了並發和線程支持,其中 std::future 和 std::promise 可用於不同線程間傳遞數據。另外別的語言或庫當中也有 promise 的概念,比如 JavaScript 和 Swift 的庫,但它們似乎跟 C++ 中的std::promise 的含義有所不同。

我的問題是,future 和 promise 這兩個概念最開始的來自哪裡?為什麼叫這個名字?有沒有什麼歷史典故?


In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program execution in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete.


The term promise was proposed in 1976 by Daniel P. Friedman and David Wise and Peter Hibbard called it eventual. A somewhat similar concept future was introduced in 1977 in a paper by Henry Baker and Carl Hewitt.


The terms future, promise, delay, and deferred are often used interchangeably, although some differences in usage between future and promise are treated below. Specifically, when usage is distinguished, a future is a read-only placeholder view of a variable, while a promise is a writable, single assignment container which sets the value of the future.

Notably, a future may be defined without specifying which specific
promise will set its value, and different possible promises may set the
value of a given future, though this can be done only once for a given
future. In other cases a future and a promise are created together and
associated with each other: the future is the value, the promise is the
function that sets the value – essentially the return value (future) of
an asynchronous function (promise). Setting the value of a future is
also called resolving, fulfilling, or binding it.

以上節選自維基百科 Futures and promises

授人以漁:我搜到這個頁面的方式是google 「concurrency promise」,搜到的時候排在第二位。

——有時你要的答案距離你只差一股溝。


Future大概是借用「期貨」得來的


推薦閱讀:

是否可以靜態鏈接動態鏈接庫?
C#如何輸出dxf文件?
C++ 中 const 的實現原理是什麼?
庫代碼中是否應該檢查malloc的返回值?
python如何畫出這樣漂亮的地圖呢?

TAG:編程 | C | 多線程 | 並發 |