tweedegolf / async-heapless Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Lines 175 to 177 in 835ae89
It is claimed that put
and take
can be called concurrently. Both methods call UnsafeCell::get()
Ensure that the access is unique (no active references, mutable or not) when casting to
&mut T
But put
calls MaybeUninit::write()
which casts it to &mut MaybeUninit<T>
. You do not guarantee that the reference is unique, given that there could be a concurrent &MaybeUninit<T>
in a concurrent call to take
.
Line 180 in 835ae89
There's no reason for the Release
in the store
above, and this can be changed to Relaxed
, as there are no writes to the shared data occurring prior to the store
operation. We know this because of core::ptr::read
:
Reads the value from src without moving it. This leaves the memory in src unchanged.
This line writes to AtomicWaker
:
Line 311 in 835ae89
There's potentially a memory ordering issue here that could lead to a missed wakeup. futures-0.3.8
memory ordering:
Calling
register
"acquires" all memory "released" by calls to wake before the call toregister
. Later calls towake
will wake the registered waker (on contention this wake might be triggered in register).For concurrent calls to
register
(should be avoided) the ordering is only guaranteed for the winning call.
This does not work for your code. Your register
could get reordered past your wake
.
To make this truly correct, you need to make sure that has_message.load()
in take
does a release and that the subsequent has_message.store()
in put
does an acquire.
Since those are not valid memory orderings in for load
and store
, you need to use fences
You need a release fence between the call to AtomicWaker::register
and has_message.load()
, and you need an acquire fence between the call to has_message.store()
and AtomicWaker::wake
.
Or you could use SeqCst
Line 311 in 835ae89
This is more of a feature request than a bug. You can reduce the amount of AtomicWaker
operations by adding a fast-path:
if let Some(message) = unsafe { self.0.take() } {
return Poll::Ready(message);
}
self.0.waker.register(cx.waker());
if let Some(message) = unsafe { self.0.take() } {
Poll::Ready(message)
} else {
Poll::Pending
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.