I think we could all speculate anything as to why threading doesn't currently work. If anyone knew it would have been fixed by now unless it were impossible to fix because of the way MicroPython works. Threading is a lot better than it used to be but there still seems to be some issues and the reasons AFAIK are not clear.I'm guessing that MPy is not directly handling race conditions with the necessary locks/etc and SPI0 on one core can stomp over the WiFi's SPIw bus and vice versa.
My suspicion is it's some kind of data corruption, one core pulling the rug from under the other. I have no idea what the actual corruption would be. The Raspberry Pi view is that one should use threading "with care to use locks for shared data", but there's no indication as to what these locks would be, how they should be used, and I'm not even convinced MicroPython provides the necessary mechanisms to do that. I have seen threading fail without even using shared data but I don't know what the current state of play is as I have stopped using threading. All I know is there are still plenty of 'threading is not doing what is expected' posts.
I would say "no; you lose all the advantages of using MicroPython instead of C".Should I be fighting this fight in C instead?
Instead I would suggest to keep using MicroPython but without threading. After all, if the RP2 didn't have two cores it's what we'd have to do anyway.
It should be possible to do all you are wanting to do on a single core though it will probably be more difficult than using threading.
Statistics: Posted by hippy — Sun Dec 01, 2024 4:07 pm