microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
727 stars 638 forks source link

Multiple forever loops have access to the common resource, concurrency #5988

Closed maxxlife closed 1 month ago

maxxlife commented 1 month ago

If a multiple forever loops have access to the common resource, how do to they define who is gonna take it first? Image

abchatra commented 1 month ago

If you go to text you will see the order of the forever loops. However each forever loop as a yield and gives the control back to another at the end of one iteration. So all 3 loops will run once at a time.

System is single thread non-preemptive system. Only one works at the time but can yield to others on its own. We put a yield at the end of forever as per design.

abchatra commented 1 month ago

question answered