Giter Club home page Giter Club logo

async-on-embedded's Issues

3-mutex-example: Deadlock

I am porting the examples to the Blue Pill (STM32F103C8T6).

In example 3-mutex I only get the following output:

B: before lock
A: before write

The expected output:

B: before lock
A: before write
A: after releasing the lock
A: yield
B: 42
DONE

The Microcontroller is currently waiting for events with the following back trace:

#0  0x08004d5e in __wfe ()
#1  0x08001390 in cortex_m::asm::wfe ()
    at /home/mkroening/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.6.2/src/asm.rs:97
#2  0x08000b02 in <async_cortex_m::unsync::mutex::MutexGuard<T> as core::ops::drop::Drop>::drop (self=0x20004d24)
    at /home/mkroening/Development/rust-embedded/async-on-embedded/async-cortex-m/src/unsync/mutex.rs:97
#3  0x08000ad0 in core::ptr::drop_in_place ()
    at /home/mkroening/.rustup/toolchains/nightly-2020-04-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ptr/mod.rs:177
#4  0x080012f2 in core::mem::drop (_x=...)
    at /home/mkroening/.rustup/toolchains/nightly-2020-04-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/mem/mod.rs:880
#5  0x080016de in _3_mutex::__cortex_m_rt_main::{{closure}} ()
    at examples/3-mutex.rs:47
#6  0x080006dc in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll (self=..., cx=0x20004f0c)
    at /home/mkroening/.rustup/toolchains/nightly-2020-04-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/future/mod.rs:66
#7  0x08000634 in core::future::poll_with_context (f=..., cx=...)
    at /home/mkroening/.rustup/toolchains/nightly-2020-04-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/future/mod.rs:84
#8  0x08001bc2 in async_cortex_m::executor::Node$LT$dyn$u20$core..future..future..Future$u2b$Output$u20$$u3d$$u20$$LP$$RP$$GT$::new::_$u7b$$u7b$closure$u7d$$u7d$::h309ac6bb8a264efb ()
    at /home/mkroening/Development/rust-embedded/async-on-embedded/async-cortex-m/src/executor.rs:162
#9  0x0800078e in <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll (self=..., cx=0x20004f0c)
    at /home/mkroening/.rustup/toolchains/nightly-2020-04-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/future/mod.rs:66
#10 0x08001ebe in async_cortex_m::executor::Executor::block_on (
    self=0x20000098 <async_cortex_m::executor::current::EXECUTOR>, f=...)
    at /home/mkroening/Development/rust-embedded/async-on-embedded/async-cortex-m/src/executor.rs:107
#11 0x08001586 in async_cortex_m::task::block_on (f=...)
    at /home/mkroening/Development/rust-embedded/async-on-embedded/async-cortex-m/src/task.rs:17
#12 0x08001972 in _3_mutex::__cortex_m_rt_main (
    X=0x20000000 <_3_mutex::__cortex_m_rt_main_trampoline::X>)
    at examples/3-mutex.rs:57
#13 0x08001912 in main () at examples/3-mutex.rs:38

The issue seems to be waiting for events after notifying any waker when dropping the MutexGuard:

self.0.wakers.notify_any();
asm::wfe();

I think this behavior (introduced in a008306) is not intended, as in other synchronization primitives we signal events instead after notifying wakers:

cx.waker().wake_by_ref();
asm::sev();

self.send_wakers.notify_one();
asm::sev();

self.recv_wakers.notify_one();
asm::sev();

I'll follow up with a PR.

What do you think?

Note that the corresponding example from the "async/await on embedded Rust" blog post does not suffer from this, as B explicitly yields after the drop, signaling events that way.

Suggestion use wfe

Hi,

I find your work really interresting so I check a bit the source file and I see that you put a TODO in executor.rs (line 110):

        // TODO try to sleep (WFI) here
        // just calling WFI here will result in missed notifications because
        // a `Waker` (called from an interrupt handler) may run just after
        // we exit the `for` loop but before WFI is called. Then the system
        // won't wake up until the *next* interrupt handler is triggered
        // (which could end up never running if the applications used only a
        // single interrupt)

After some search on the web I see that effectively WFI on cortex-m0 doesn't do any check before going in sleep mode, not like on cortex-m3 where it should work.

But it look like WFE does'nt have this problem and could be used.

I'm probably not seeing another problem but I wanted to try.

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.