tinygo
tinygo copied to clipboard
internal/task: use a lock-free queue
This changes task.Stack and task.Queue to use atomic compare-and-swap operations. With this change, Push can also be executed safely from multiple threads/cores. Additionally, the queue is actually LIFO now (not sure what I was thinking before).
Not entirely sure about this yet.
Oops, i meant FIFO not LIFO. Also xtensa seems to still need work?
Size impact statistics:
- Arduino Uno Blinky (tasks): adds 172 bytes
- Arduino Nano 33 Blinky: adds 84 bytes
- Metro M4 Airlift Blinky: adds 40 bytes
- ESP32-Mini32 Blinky: adds 40 bytes
- Linux Channel Test: adds 76 bytes
Out of curiosity: do you have plans to use the changes in this PR?
I am not intending to do anything specific right now, but this might be useful once we want to implement multicore support for something.
Any new features this will add?
Right now:
- The queue. . . is actually a queue instead of a weird mostly-stack
- On devices with support for atomics, this does not need any critical sections
The Push operation can also be safely called concurrently. . . but only if the tasks are pinned safely (which is currently an issue, but this is more of a future thing).
This has been rebased now that #2307 is merged
I still need to test this fully on AVR though
Now that #2458 and #2459 are in, I consider this ready.
Seems like this is perhaps not working correctly on the HiFive1b? I tried several times, and also ran some other test code successfully.
@aykevl If this is correct, would you be willing to merge it? I'm going to try implementing threads again.
I think we can close this now? I don't see what features it adds or what bugs it fixes, while it does increase binary size.