Namespaces
Variants
Actions

Talk:cpp/thread/promise/set value

From cppreference.com
< Talk:cpp‎ | thread‎ | promise

Regarding Example

Are there written guidelines for examples anywhere?

Having commented on the example for unique_lock::lock() I don't want to be known as the Example Complaint Guy but here is another example that is opaque enough that I doubt that it will be helpful to many.

This is a complicated piece of code that does little to illuminate the use of set_value() in the common use of setting a value that is then read with get(). I do think that an example of set_value(void) is useful, especially if it's use is the prominent part of the example. Perhaps both ought to occur in the same example.

As with unique_lock::lock() I will wait some time after this post before just diving in and changing someone else's work. Arbalest (talk) 18:31, 23 February 2014 (PST)

Good feedback on stuff like this is always welcome, Arbalest. :) In this case, I'd tend to agree with you that it would be nice to see a set/get example, as opposed to code that just uses promises for signaling. The trick is going to be finding a way to do so without writing a novel-length batch of code. --Nate (talk) 19:30, 24 February 2014 (PST)

[edit] "The operation is atomic" is misleading

I think this phrase and the example are misleading, because the operation is not atomic (so as "set_exception" too). Here is the link on StackOverflow with good explanation http://stackoverflow.com/questions/12522928/non-obvious-lifetime-issue-with-stdpromise-and-stdfuture

I suppose we could use a more standardese-like wording (The set_value, set_exception, set_value_at_thread_exit, and set_exception_at_thread_exit member functions behave as though they acquire a single mutex associated with the promise object while updating the promise object.) --06:09, 9 December 2015 (PST)
Well, the standard says "atomically stores the value r in the shared state and makes that state ready (30.6.4)."... T. Canens (talk) 09:08, 9 December 2015 (PST)
close