Skip to content

std: expand the Share docs to make them more precise. #13070

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

Merged
merged 1 commit into from
Mar 25, 2014

Conversation

huonw
Copy link
Member

@huonw huonw commented Mar 22, 2014

std: expand the Share docs to make them more precise.

And give some examples about exactly what's Share and what's not.

/// For cases when one does need thread-safe interior mutability,
/// types like the atomics in `std::sync` and `Mutex` & `RWArc` in the
/// `sync` crate do ensure that any mutation cannot cause data races.
/// Hence these types are `Share`.
Copy link
Member

Choose a reason for hiding this comment

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

This may want to change the mention of RWArc to Arc and/or RWLock in preparation for my sync rewrite.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, whoops, I was actually meaning to write those new forms, but habit hijacked my keyboard.

(Updated.)

@alexcrichton
Copy link
Member

cc @nikomatsakis, just want to make sure you agree with this. Otherwise, this looks good to me.

/// A somewhat surprising consequence of the definition is `&mut T` is
/// `Share` (if `T` is `Share`) even though it seems that it might
/// provide unsynchronised mutation. When in an aliasable spot as `&
/// &mut T`, a mutable reference becomes read-only, as if it were a `&
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could you put the & &mut T and & &T in the same line? Just to make it more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I reworded this section to get the line breaks to line up nicer; just for you, @flaper87 ;P

(BTW, it did render correctly in the HTML even with the linebreaks.)

@flaper87
Copy link
Contributor

very nice, thanks for expanding the Share docs

@nikomatsakis
Copy link
Contributor

These look good. My only caveat is that perhaps we should mention that if you are writing your own type with interior mutability, you must use Unsafe<T> (as well as opting out of Share).

And give some examples about exactly what's `Share` and what's not.
@huonw
Copy link
Member Author

huonw commented Mar 25, 2014

Updated the last paragraph to include Unsafe.

bors added a commit that referenced this pull request Mar 25, 2014
std: expand the `Share` docs to make them more precise.

And give some examples about exactly what's `Share` and what's not.
bors added a commit that referenced this pull request Mar 25, 2014
std: expand the `Share` docs to make them more precise.

And give some examples about exactly what's `Share` and what's not.
@bors bors closed this Mar 25, 2014
@bors bors merged commit e9475b5 into rust-lang:master Mar 25, 2014
@huonw huonw deleted the share-doc branch June 27, 2014 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants