GithubHelp home page GithubHelp logo

async-heapless's People

Contributors

lucus16 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

async-heapless's Issues

Fast-path can reduce the amount of AtomicWaker operations

self.0.waker.register(cx.waker());

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
        }

Potentially missed wakeups due to memory reordering

This line writes to AtomicWaker:

self.0.waker.register(cx.waker());

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 to register. Later calls to wake 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

Uniqueness requirement for UnsafeCell aliases violated in oneshot.rs

/// NOTE(unsafe): This function must not be used concurrently with itself,
/// but it can be used concurrently with put.
pub unsafe fn take(&self) -> Option<T> {

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.