apollo icon indicating copy to clipboard operation
apollo copied to clipboard

why cyber rt use for (;;) here?

Open fengmao31 opened this issue 1 year ago • 2 comments

why cyber rt use for (;;) here? it looks like that it cannot run loop here because the "if, else" cover all the conditions in this loop. Also I found only this part and io part use yeild code, it is looks like that the coroutines is designed for these two parts. Maybe coroutines not necessary for cyber rt. image

fengmao31 avatar Jan 29 '24 01:01 fengmao31

Actually, I didn't understand your question. The for loop will wait for data and execute. If there is no data, it will sleep. There is no problem with this.

You can describe your problem in detail for better discussion

daohu527 avatar Feb 01 '24 09:02 daohu527

I misunderstand the coroutine design in cyber rt in the last time. In the classic scheduler, though cyber rt use the coroutine design, the the classic scheduler don't take advantage of the benefits of concurrency. When the thread get the READY coroutine from MULTI_PRIO_QUEUE, it can get any coroutine every time. This cause a protblem that the callback will be run in random processer thread when we keep running publish and subscribe communication, rather than the callback is run in a same thread. Maybe the design is meant to choreography scheduler?

fengmao31 avatar Feb 05 '24 09:02 fengmao31

In the classic scheduler, multiple processors compete for access to a thread-safe coroutine queue (protected by a mutex) where coroutines are prioritized based on their priority levels, with higher-priority coroutines being selected for execution after the competition.

DieYoungWsn avatar Mar 05 '24 04:03 DieYoungWsn

I test it one moth age. If delete the for (;;), the CRoutine will be finished.

This keep the life of the CRoutine. The yeild make the thread jump from the for (;;) to other CRoutine.

fengmao31 avatar Mar 06 '24 14:03 fengmao31