5

The interface for std::future::then in the paper N3784 included an overloaded version that accepted an executor (described more here in N3562) as a parameter. So if you wanted more control over which thread the callback was executed on you could do so.

But the official document that goes over all the features that are in the concurrency TS here http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0159r0.html#futures.unique_future does not include that overload for .then() and doesn't mention executors at all. It says

When the object's shared state is ready, the continuation INVOKE(DECAY_COPY(std::forward<F>(func)), std::move(*this)) is called on an unspecified thread of execution with the call to DECAY_COPY() being evaluated in the thread that called then.

Why does the interface not offer precise control of how the closure is executed? How then can one exercise control over which thread runs the callback? Why the change from the proposed version?

Note I am not sure if the concurrency TS paper I linked to is the latest one, but cppreference does not mention executors anywhere either

Edit If someone has a reference or reason in some C++ standards paper that mentions the reason for not continuing with executors, that would be great!

Curious
  • 20,870
  • 8
  • 61
  • 146
  • 1
    I'm very skeptical that this is on-topic for Stack Overflow. – Xirema May 25 '17 at 20:26
  • 3
    @Xirema Why do you say that? If the standards committee thinks that using executors is bad design for most programming use cases, then it is good to know why they think that. – Curious May 25 '17 at 20:27
  • Regarding the vote to close my question, it specifically involves a tool used for programming in standard C++, so I don't think this question should be closed for that reason. – Curious May 25 '17 at 20:28
  • Because this website's principal purpose is for debugging code. If you want to know why the committee made a questionable design decision, you're better off asking them directly or going to one of the other Stack Exchange websites that handles these kinds of questions. – Xirema May 25 '17 at 20:30
  • 1
    @Xirema there are tons and tons of such questions on stackoverflow that are highly viewed and have tons of upvotes, for example https://stackoverflow.com/questions/6687388/why-do-some-people-use-swap-for-move-assignments/6687520#6687520, https://stackoverflow.com/questions/16350473/why-do-i-need-stdcondition-variable/16350623#16350623 and something almost exactly similar https://stackoverflow.com/questions/38894020/why-arent-parts-of-the-concurrency-ts-going-in-c17 if there is a callback execution paradigm that C++ is trying to promote then why not be aware of what it is? – Curious May 25 '17 at 20:34
  • @Xirema this question for example is about C++ standardization and has nothing to do directly with debugging code https://stackoverflow.com/questions/38060436/what-are-the-new-features-in-c17 – Curious May 25 '17 at 20:37
  • Granted, this website is bad at following its own rules. But either way, you're misunderstanding my argument. I'm not saying that this is unworthy to be discussed, I'm saying that Stack Overflow isn't meant to handle these kinds of questions. I can say pretty confidently that the [Software Engineering](https://softwareengineering.stackexchange.com/) exchange site would probably be way more appropriate for a question like this. – Xirema May 25 '17 at 20:41
  • 1
    @Curious: "*there are tons and tons of such questions on stackoverflow*" The last one is the only one like this one, where someone is asking about why the standard committee did something, rather than what the purpose of a feature is. The former can only effectively be answered by standards committee members (the most upvoted answer on your last one is ultimately just a guess). – Nicol Bolas May 25 '17 at 20:42
  • The examples you're citing aren't really the same thing, anyways: they're providing objective answers to specific questions. Unless this question gets a response from one of the specific committee members who worked on that change, you're only going to get speculation and subjective responses. On softwareengineering.stackexchange.com, that's 100% fine. Not so much here. – Xirema May 25 '17 at 20:43
  • @Xirema why do you think that the reason for such a change can not be present in a paper on the open-std.org website? That would be an objective answer. I even edited my question to ask that – Curious May 25 '17 at 20:44
  • @Curious: For example, I have "an answer" to this question. But it would still only be a *guess*. Namely, that they spun executors off [into this paper.](http://wg21.link/P0443) Oh sure, it has evidence: the fact that there's a paper specifically about executors, which includes `future::then` and such. But that doesn't mean that's why they removed them from the currency TS (assuming they did at all, since the final TS is behind a paywall). – Nicol Bolas May 25 '17 at 20:44
  • @Curious: "*why do you think that the reason for such a change can not be present in a paper on the open-std.org website?*" It could be. But since all papers are public knowledge, you could do the googling for yourself. Here: I'll even help you out by [linking you to all of the papers](http://www.open-std.org/JTC1/SC22/WG21/docs/papers/). All *several thousand* of them. – Nicol Bolas May 25 '17 at 20:45
  • @NicolBolas I tried, and was unable to find it. If something is public knowledge then it is not fit to be on stackoverflow? – Curious May 25 '17 at 20:47
  • @NicolBolas This argument is folly, if you think I should delete the question I will. – Curious May 25 '17 at 20:48
  • @NicolBolas Also there are so many good on topic questions here that look for references from the standard (which is public information) regarding some issue, something that leads to a compiler error. I am looking for something similar, a quote that explains why they are out of the standard. – Curious May 25 '17 at 20:50
  • 2
    @Xirema: "Because this website's principal purpose is for debugging code." No, debugging code is not the principle purpose. (In fact, debugging questions used to be discouraged until a couple years ago (when we lost the "Too Localized" close reason) and now are only grudgingly accepted if they fall within certain constraints.) The purpose of this site is to ask and answer programming questions with the intent of building a knowledge base that will help future users. – Adrian McCarthy May 25 '17 at 20:57
  • 2
    IIRC the design of executors were fairly controversial, so they got taken out until people can reach agreement. Otherwise the rest of the concurrency TS will be blocked. – T.C. May 25 '17 at 21:00
  • @T.C. Thanks! What about it made it controversial? Also, do you have any idea if the `std::future` interface is planning on exposing some API that allows people to specify how they want their callbacks executed other than just `std::launch` (which also does not seem to be in the TS)? – Curious May 25 '17 at 21:01
  • @AdrianMcCarthy [*"a specific programming problem, or a software algorithm, or software tools commonly used by programmers; and is a practical, answerable problem that is unique to software development"*](https://stackoverflow.com/help/on-topic). Ostensibly, the OP's question falls under the third category, but because it tends towards attracting subjective, opinionated answers, it belongs on a site like SoftwareEngineering, not StackOverflow. – Xirema May 25 '17 at 21:02
  • @Xirema the specific programming problem here is how one can specify which thread the callback provided to `std::future::then` is ran on. Since executors got taken out. Is that not a good question to ask? If so how do you suggest I modify my question to make it appropriate? – Curious May 25 '17 at 21:04
  • 1
    @Curious Then your question is poorly framed. If the question is solely "how do I do this thing", then you need to show code demonstrating how you *tried* to do it, and how it isn't doing what you intended it to do. All the other stuff (*"Why were executors removed from the spec?"*) is irrelevant, and belongs in its own question on a different site. – Xirema May 25 '17 at 21:10
  • @Xirema I disagree, executors helped in achieving what I mentioned, and now they are removed. There must be some thought about what alternative would be superior, and why executors are bad. It is good to know both things. And they are both essential to answering the question holistically – Curious May 25 '17 at 21:12
  • @Curious If you consider those questions important, then go ask SoftwareEngineering.stackexchange.com what they think of the decision to remove Executors (or, apparently, split them off into their own paper?). As far as I'm concerned, "How do I do 'x'?" is a wholly different question than "why did they remove the previous method of doing 'x'?" – Xirema May 25 '17 at 21:16
  • 1
    See, e.g., [N4032](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4032.html) and [N4046](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4046.pdf). – T.C. May 25 '17 at 21:17
  • @Xirema when referring other sites, it is often helpful to point that [cross-posting is frowned upon](https://meta.stackexchange.com/tags/cross-posting/info) – gnat May 25 '17 at 21:52
  • @gnat cross-posting refers to taking the same question and posting it in multiple places. It has little bearing on "this question was inappropriate for one site and is better elsewhere". – Xirema May 25 '17 at 21:54

1 Answers1

2

Why the change from the proposed version?

The TSes are trial balloons for features approaching standardization but may not be in final form yet. They are a chance for the standards committee to get experience to see what does and doesn't work in the real world.

Since there is at least one newer proposal for executors, it seems the working group wasn't satisfied with executors as they were in the TS and are refining them before standardization.

How then can one exercise control over which thread runs the callback?

Right now, it seems you'd have to depend on a language or library extension or roll your own. I haven't studied the proposal enough to say how you would do it if the proposal becomes part of the standard, but it looks like then_execute, which can be a free function or a member of the executor object, would be the key.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175