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
Introduce tokio-sync crate containing synchronization primitives. #839
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not finished reviewing the whole branch, but here are some minor nits and other non-blocking feedback on what I've reviewed to this point.
Shouldn't this kind of thing be futures-sync instead? |
@arthurprs given that it will be maintained by the Tokio team, it makes more sense to have it under the Tokio project IMO. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions:
-
What's the reason for exporting
AtomicTask
, i.e. when should one use it overfutures::task::AtomicTask
? -
Any reason why the API for acquiring permits in semaphore is the way it is? Why not have
Semaphore::acquire(&self) -> Acquire<'_>
, whereAcquire
is a future that returns aPermit
on success, and droppingPermit
releases it? -
Would it be better for
Sender::poll_cancel()
to be namedSender::poll_close()
? One of my pet peeves with channels in general is that there are so many words that mean the same thing: close, disconnect, cancel (also see here). :)
It makes me feel more comfortable maintaining this infrastructure piece as all of Tokio relies on it. It has been updated to be checked w/ loom. There have been buggy changes merged into the AtomicTask in the futures crate in the past.
There could be value in providing an API like that, but it would incur additional run-time cost. The proposed API has little run-time cost and is intended to be used as part of other data structures (like
I think that would be a good change. I will apply to the PR. |
Fair enough, that makes sense. It'd be good to eventually move our changes and loom-verified stuff back into
Fine by me. API design is hard. Let's keep the current semaphore and reevaluate it once we gain experience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! I'm happy with the current state of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
There's any plans to add mpmc channels to this library? |
Sent from my T-Mobile 4G LTE Device
…-------- Ohcriginal message --------
From: Mauri de Souza Nunes <notifications@github.com>
Date: 1/24/19 5:54 AM (GMT-07:00)
To: tokio-rs/tokio <tokio@noreply.github.com>
Cc: Subscribed <subscribed@noreply.github.com>
Subject: Re: [tokio-rs/tokio] Introduce tokio-sync crate containing synchronization primitives. (#839)
There's any plans to add mpmc channels to this library?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#839 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AoPIUcsyh_7svNaYfweD-HJ1uSUlow13ks5vGa0egaJpZM4Z4b5N>.
|
@@ -0,0 +1 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being that late, but what was the reason for this file and tx.rs
, if both are empty and not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... just forgot to delete them I guess.
@mauri870 at some point probably. Just have to come up w/ a strategy that works. |
Introduce a tokio-sync crate containing useful synchronization primitives for programs written using Tokio.
The initial release contains:
AtomicTask
primitive.The
oneshot
andmpsc
channels are new implementations providing improved performance characteristics. In some benchmarks, the new mpsc channel shows up to 7x improvement over the version provided by thefutures
crate. Unfortunately, theoneshot
implementation only provides a slight performance improvement as it is mostly limited by thefutures
0.1 task system. Once updated to thestd
version ofFuture
(currently nightly only), much greater performance improvements should be achievable byoneshot
.Additionally, he implementations provided here are checked using Loom, which provides greater confidence of correctness.