chan.waiting `push_front` instead of `push_back`? Thread scheduling
Right now if there is no Task in the queue, threads or rather Signals are being put at the end of the queue. this means that in a scenario where there is many recv threads, they will round robin over one another, resulting in a scenario where all of them have to be waken one by one.
I think it would be slightly more beneficial if the push happened onto the front instead, resulting in a case where 1 of the threads is active the most, rather than round robin. Leading to maybe less cache misses.
I am using channel in a code that usually around 10 threads are active, but in the extreme cases it may be thousands of them - that would wait on a blocking operation to complete.
If the push happened to the front, only 10 threads would be active most of the time.
I think th e change entails changing how `fn recv` works, by doing a `push front` around line 598.
关闭于 2024-06-27 1 条评论