-
Notifications
You must be signed in to change notification settings - Fork 653
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
NIOSendableBox: allow off-loop initialisation iff Value is Sendable #2753
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 find it weird to use a factory method here personally. I would prefer using an init here. I also see little value in having this constrained to
Sendable
sinceSendable
types can freely be shared between threads.I expected a spelling like this
This would allow moving an non-Sendable value into an EL's isolation region which is dynamically enforced by the LoopBoundBox.
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.
init
s are unconstrained but have to run oneventLoop
. And themakeBoxSendingValue
ones can be run off the EL with various constraints (eitherSendable
orsending
)sending
isn't ready yet (Give NIOLoopBoundBox asending
off-EL initialiser once compiler is ready #2754)Sendable
values. It's not about sending the values around,NIOLoopBoundBox
is about mutating the values. Typically this is for thread-safe network clients/servers that have a state machine which only gets accessed on a particular EL. So current:var state: State // only access on self.eventLoop
; new:let state: NIOLoopBound<State>
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 understand your goal but IMO
NIOLoopBoundBox
with an alreadySendable
value does not make sense. What you want here is just a plain oldBox<T>
that is conditionallySendable
onT
. If the boxed value is alreadySendable
then the loop enforcement adds no value since the type is already thread safe. The storage might not i.e. thevar
but the only thing needed for that is to make it a let through adding reference semantics.let boxed = Box<MySendableType>
is totally safe.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.
That's not accurate.
class Box<T> { var value: T }
cannot be Sendable (without synchronisation), you get mutation and sharing.class NIOLoopBoundBox<T> { var value: T /* checks EL on all accesses */ }
is alwaysSendable
because it checks that all accesses are on the same EL. So you get mutation but no sharingThere 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 got no objection to the PR in its current state, but I'm not going to approve because I'd like to see @FranzBusch and @weissi get aligned here.
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 am fine with taking this as is.