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

Documentation: MiniTokio doesn't compile #734

Closed
lsioctl opened this issue Nov 25, 2023 · 3 comments
Closed

Documentation: MiniTokio doesn't compile #734

lsioctl opened this issue Nov 25, 2023 · 3 comments
Labels

Comments

@lsioctl
Copy link

lsioctl commented Nov 25, 2023

Description

In the Async in Depth documentation, this part
doesn't compile:

struct Task {
    // The `Mutex` is to make `Task` implement `Sync`. Only
    // one thread accesses `future` at any given time. The
    // `Mutex` is not required for correctness. Real Tokio
    // does not use a mutex here, but real Tokio has
    // more lines of code than can fit in a single tutorial
    // page.
    future: Mutex<Pin<Box<dyn Future<Output = ()> + Send>>>,
    executor: mpsc::Sender<Arc<Task>>,
}

For what I understand, it is because of ArcWake needs Task to be Sync, and mpsc::Sender is only Send, not Sync.

I found a quick workaround with wrapping the Sender in a Mutex so all members of Task are Sync.

I can submit a two liners PR if you fancy.

@Darksonn Darksonn transferred this issue from tokio-rs/tokio Nov 25, 2023
@Darksonn
Copy link
Contributor

Actually, mpsc::Sender is now Sync as of rustc 1.72.0. Please see #727.

@Darksonn Darksonn closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2023
@lsioctl
Copy link
Author

lsioctl commented Nov 25, 2023

Completely missed that ! Sorry and thank you.

@Darksonn
Copy link
Contributor

No worries. Thank you for going to the effort to let us know about a potential issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants