Giter VIP home page Giter VIP logo

Comments (5)

ivmarkov avatar ivmarkov commented on July 18, 2024 1

No, I have simply forgotten about it. Will fix shortly.

from esp-idf-hal.

ivmarkov avatar ivmarkov commented on July 18, 2024

But that's still strange. I don't know embassy-executor in detail, but why is it requiring the Future-s to be Send? After all, they ALL run in a single thread, so to say. This is weird?

from esp-idf-hal.

ivmarkov avatar ivmarkov commented on July 18, 2024

Can you paste your code here? Or upload it somewhere? I suspect there is something else fishy going on (not that the async driver should not be Send, but with embassy, that should not be a prob).

from esp-idf-hal.

MikiLoz92 avatar MikiLoz92 commented on July 18, 2024

Oh we're not using embassy-executor, but actually using your edge-executor crate! We're using the same PriorityExecutor defined under the examples, as a matter of fact. And that does require Send.

In fact, since we're using just one thread to run all our tasks, I just removed the Send requirement for the futures under that executor, and made it use LocalExecutors, and now it compiles:

pub struct PriorityExecutor<'a> {
    ex: [LocalExecutor<'a>; 3],
}

unsafe impl<'a> Sync for PriorityExecutor<'a> {}

impl<'a> PriorityExecutor<'a> {

    pub const fn new() -> PriorityExecutor<'a> {
        PriorityExecutor {
            ex: [LocalExecutor::new(), LocalExecutor::new(), LocalExecutor::new()],
        }
    }

    pub fn spawn<T: 'a>(
        &self,
        priority: Priority,
        future: impl Future<Output = T> + 'a,
    ) -> Task<T> {
        self.ex[priority as usize].spawn(future)
    }

    pub async fn run(&self) {
        loop {
            for _ in 0..200 {
                let t0 = self.ex[0].tick();
                let t1 = self.ex[1].tick();
                let t2 = self.ex[2].tick();

                t0.or(t1).or(t2).await;
            }

            future::yield_now().await;
        }
    }
}

from esp-idf-hal.

ivmarkov avatar ivmarkov commented on July 18, 2024

Yep, exactly! I can't imagine anybody using the parallel executor in embedded. I mean, if you really need to utilize multiple threads, you are probably better off with a separate LocalExecutor in each thread, and then if you need the futures in these executors to share stuff, use Signal or Channel or something from embassy-sync. And then only the futures of the embassy-sync synchronization primitives need to be Send (and you can easily achieve this with using them with a CriticalSectionRawMutex or your own RawMutex impl based on std::sync::Mutex.), but not the rest.

from esp-idf-hal.

Related Issues (20)

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.