Uh oh!
There was an error while loading. Please reload this page.
Use UnsafeCell in ThreadRng - #285
Conversation
pitdicker
commented
Mar 9, 2018
This is actually a small PR, if you think away the commits it is made on top of.
So I think the API of |
burdges
commented
Mar 9, 2018
Actually why There are a couple minor hiccups with using First, you must ensure Second, I think I suppose |
pitdicker
commented
Mar 10, 2018
I was already wondering why the existing code was using I seems we can't make |
dhardy
commented
Mar 10, 2018
Good point about As I understand it, there is a "primary instance" of the |
vks
commented
Mar 12, 2018
Couldn't you use |
pitdicker
commented
Mar 13, 2018
Thanks all for the comments. I will clean up this soon(ish).
Ah, nice! So I could use Still I think I'll go with |
dhardy
commented
Mar 16, 2018
@pitdicker you can rebase now |
f5cbc91 to
8ce871bComparepitdicker
commented
Mar 17, 2018
Rebased. |
dhardy
commented
Mar 17, 2018
The use of I think I'm happy with the PR as it stands and comments are positive, so merge if you think it's ready. |
I wondered if we should consider an We cannot use We could make |
dhardy
commented
Sep 10, 2018
Check #579; we don't even need Yes I think we could make |
Very nice! because the first permits simply borrowing the |
This is based on top of #281, but only the last commit is interesting. Also this PR is in no way mergeable, but I wanted to get your opinion if it even is sensible.
Using
UnsafeCellinstead ofRefCellinsideThreadRngmakes the performance overhead ofThreadRngand theReseedingRngwrapper in-between just about negligible.Compare:
The idea is that we currently use
RefCell, and panic if a second mutable borrow insideThreadRngoccurs. I can't really think of a situations where that can happen, see the comment in the last commit. In that case it should also be safe to useUnsafeCelldirectly, with less overhead. But I am not sure what happens during panics...