Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7d364aa
RFC: add Async trait and task system to libcore
aturon Apr 24, 2018
0ded7b7
Revamp RFC to one-trait approach
aturon May 30, 2018
01ce3f9
Revamp for stabilization
aturon Nov 9, 2018
bb242c8
Address nits
aturon Nov 9, 2018
1c8961e
Typo
aturon Nov 10, 2018
96ba924
Move the descriptions of LocalWaker and Waker and the primary focus.
Matthias247 Nov 18, 2018
2ff9713
Add a comment why RawWaker is used
Matthias247 Nov 18, 2018
e40dab4
Update the section about ArcWake
Matthias247 Nov 18, 2018
405361a
fix sentence
Matthias247 Nov 18, 2018
4cbbba8
Consume LocalWakers on conversion to Waker
Matthias247 Nov 18, 2018
de6b949
Add suggestions around syntax.
Matthias247 Nov 19, 2018
fdb41f8
Allow clone to alter the vtable
Matthias247 Nov 19, 2018
af29613
update wording
Matthias247 Nov 20, 2018
04695be
Apply suggestions from code review
Matthias247 Dec 8, 2018
e025c59
Fix ArcWake methods
Matthias247 Dec 8, 2018
db5f882
Add additional clarification around RawWaker
Matthias247 Dec 8, 2018
e1d2b8f
Remove LocalWaker and simplify the RawWakerVTable
cramertj Jan 8, 2019
05db198
Merge pull request #16 from cramertj/less-waker
cramertj Jan 23, 2019
af3da95
Cleanup
cramertj Jan 23, 2019
eff2eca
Merge pull request #17 from cramertj/futures-cleanup
cramertj Jan 23, 2019
a268c75
typo fix
dyxushuai Jan 26, 2019
834f0cd
typo
dyxushuai Jan 26, 2019
4e9e72c
Merge pull request #19 from dyxushuai/patch-2
aturon Jan 28, 2019
4825174
Merge pull request #18 from dyxushuai/patch-1
aturon Jan 28, 2019
f50c0c4
Apply suggestions from code review
cramertj Mar 11, 2019
e7eaea1
RFC 2592
cramertj Mar 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address nits
  • Loading branch information
aturon committed Nov 9, 2018
commit bb242c8cc6ee2f873e6f95d1bf02cedf4cded468
29 changes: 26 additions & 3 deletions 29 text/0000-futures.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,33 @@ pub trait Wake: Send + Sync {
///
/// Executors generally maintain a queue of "ready" tasks; `wake_local` should place
/// the associated task onto this queue.

unsafe fn wake_local(self: &Arc<Self>)
}
```

To see how this might be used in practice, here's a simple example sketch:

```rust
struct ExecutorInner {
sync_ready_queue: SynchronousQueue,
optimized_queue: UnsafeCell<Vec<Task>>,
}

struct Task {
future: ...,
executor: Arc<ExecutorInner>,
}

impl Wake for Task {
fn wake(self: &Arc<Self>) {
self.executor.sync_ready_queue.push(self.clone());
}
unsafe fn wake_local(self: &Arc<Self>) {
(&mut *self.executor.optimized_queue.get()).push(self.clone())
}
}
```

The use of `&Arc<Self>` rather than just `&self` makes it possible to work directly with
the trait object for `Wake`, including cloning it. With `UnsafeWake` below, we'll see
an API with greater flexibility for the cases where `Arc` is problematic.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first thought this would refer to the example just above, but there is no trait object there, is there? An example for what this remark refers to would be nice.

I fist thought one could just add Clone to the supertraits, but I guess that would destroy object safety.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalWaker and Waker are themselves trait objects. Both work out to something like *const UnsafeWake. Implementing the Wake trait gives you an implementation of UnsafeWake for Arc<YourType>.

This API can be awkward to work with in some edge cases though where you want to change the vtable without changing the underlying pointed to type. @aturon is working on a modification of the proposal, and I've suggested considering that we use a more C-like manual vtable instead. This would allow us more flexibility, make type-punning-to-change-the-vtable unnecessary, and removes the hairy questions around whether or not *const UnsafeWake must have a valid vtable.

Expand All @@ -208,14 +230,15 @@ impl Waker {
}

/// A `LocalWaker` is a handle for waking up a task by notifying its executor that it is ready to be run.

///
/// This is similar to the `Waker` type, but cannot be sent across threads. Task executors can use this type to implement more optimized singlethreaded wakeup behavior.

impl LocalWaker {
/// Wake up the task associated with this `LocalWaker`.
pub fn wake(&self);
}

/// You can upgrade to a sendable `Waker` at zero cost, but waking through a `Waker` is more expensive
/// due to synchronization.
impl From<LocalWaker> for Waker { .. }
```

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.