Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how task::future_result works #3725

Closed
catamorphism opened this issue Oct 11, 2012 · 17 comments
Closed

Change how task::future_result works #3725

catamorphism opened this issue Oct 11, 2012 · 17 comments
Labels
A-concurrency Area: Concurrency C-cleanup Category: PRs that clean code up or issues documenting cleanup.

Comments

@catamorphism
Copy link
Contributor

A FIXME note said "Once linked failure and notification are
// handled in the library, I can imagine implementing this by just
// registering an arbitrary number of task::on_exit handlers and
// sending out messages." The bugs this referred to are closed, so nothing's blocking this.

@bblum
Copy link
Contributor

bblum commented Oct 19, 2012

There isn't presently a mechanism for atexit handlers, which would be required to do it the way the comment suggests. Alternatively the notify_port could just be replaced with a list of notify_ports.

Either way, seems useful to enable multiple tasks futuring on a single task's exit.

@brson
Copy link
Contributor

brson commented Oct 19, 2012

I think the approach in that comment is obsolete with pipes. Now I prefer changing the task notification to a pipes::OneShot (with a different name), and have a SharedOneShot type, like SharedChan. I'm not sure where Future fits in, but OneShot seems to be the appropriate type for one-time notifications.

@brson
Copy link
Contributor

brson commented Oct 19, 2012

And of course the callback interface of future_result is very awkward still.

@bblum
Copy link
Contributor

bblum commented Oct 19, 2012

SharedOneShot would kind of defeat the purpose of oneshot pipes. Only one task could receive a message on it; the rest would fail. Oneshots would work with the "list of notify_ports" approach.

Having multiple tasks wait on a single condition is the "condition variable" model (cond-wait/cond-broadcast) -- we have condvars, but they are in libstd. They are just implemented with a list of oneshots, though, so I think having a list of notify_portspipes and making them oneshot makes the most sense.

@bblum
Copy link
Contributor

bblum commented Oct 19, 2012

(re: callback interface) yeah, I wasn't happy with that at all. that was the one thing the builder interface did better.

@brson
Copy link
Contributor

brson commented Oct 19, 2012

That is not how I was thinking SharedOneShot would work. Maybe that's not the right name, since it isn't the same as SharedChan. I want a shared object that, the first time it is waited on performs the recieve, and subsequent times just looks at the value. Maybe a better composition would be some kind of Mutex<Future<T>> where Future can take a OneShot (Future currently only takes it's own pipe protocol).

@brson
Copy link
Contributor

brson commented Oct 19, 2012

This is similar to the problem with sharing futures of images in servo. Somebody has to receive the value the first time, then everybody else becomes a reader.

@bblum
Copy link
Contributor

bblum commented Oct 19, 2012

Oh, right, and all other waiting tasks instead wait at the boundary of the MutexARC (which uses pipes internally). Sure. Also has the advantage of not needing to add new machinery and also not needing to call future_result at spawn-time multiple times (instead you can call clone() whenever you want).

@pnkfelix
Copy link
Member

Visited for bug-triage, 2012jun24. Comment still exists in libstd/task/mod.rs. (And of course, brian's comment above indicates that he would prefer approach via pipes; I'm guessing until that is done, it is best to leave the comment in place as is, so people can see the dialogue here.)

@huonw
Copy link
Member

huonw commented Sep 18, 2013

Triage: still a problem.

@emberian
Copy link
Member

The readme is still there. Should this remain, @alexcrichton? Seems... mostly obsolete?

@alexcrichton
Copy link
Member

Hm, this doesn't quite make sense to me. The std::task api needs to be scrutinized regardless, but I would personally punt this to stability attributes.

Nominating for removal from the 1.0 milestone because I think that this should be taken care of with stability attributes instead.

@ehsanul
Copy link
Contributor

ehsanul commented Feb 24, 2014

Is the current alternative to somehow use notify_chan for tasks to monitor each others' failure? I have two tasks, parent and child, which do not communicate with each other, but need some sort of linked failure - if one fails, the other should as well. There is no Chan to propagate failure between the tasks, and it's unclear to me how to do this with the current tasks api.

@pnkfelix
Copy link
Member

We're going to leave it as is, on the 1.0 milestone.

@brson
Copy link
Contributor

brson commented Jun 11, 2014

Nominating for removal from milestone. future_result is sane enough now that it's not the end of the world to be stuck with it forever (it used to require capturing in- and moving back out of a closure).

I still would rather this be a spawn_result method or something, so it doesn't break the builder pattern.

@aturon
Copy link
Member

aturon commented Jun 12, 2014

@brson Just a heads-up: I have a patch in progress that revamps the task spawning API along exactly the lines you're suggesting, among other things. (I was waiting for librustrt to land before completing this.)

+1 on milestone removal.

@pnkfelix pnkfelix removed this from the 1.0 milestone Jun 12, 2014
@pnkfelix
Copy link
Member

Removing from milestone.

We are trying to systemically review our libraries and mark them with stabilty attributes as appropriate. Leaving as P-backcompat-libs in hopes that it will be caught when all such tagged issues are reviewed.

aturon added a commit to aturon/rust that referenced this issue Jun 18, 2014
This patch consolidates and cleans up the task spawning APIs:

* Removes the problematic `future_result` method from `std::task::TaskBuilder`,
  and adds a `try_future` that both spawns the task and returns a future
  representing its eventual result (or failure).

* Removes the public `opts` field from `TaskBuilder`, instead adding appropriate
  builder methods to configure the task.

* Adds extension traits to libgreen and libnative that add methods to
  `TaskBuilder` for spawning the task as a green or native thread.

Previously, there was no way to benefit from the `TaskBuilder` functionality and
also set the scheduler to spawn within.

With this change, all task spawning scenarios are supported through the
`TaskBuilder` interface.

Closes rust-lang#3725.

[breaking-change]
@aturon aturon closed this as completed in a23511a Jun 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-concurrency Area: Concurrency C-cleanup Category: PRs that clean code up or issues documenting cleanup.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants