eio icon indicating copy to clipboard operation
eio copied to clipboard

Implement simple atomic stream select

Open dermesser opened this issue 1 year ago • 2 comments

for #577, to supersede #578.

I want to emphasize that this change is based on my likely too superficial understanding of the library. It is likely that there exists a more elegant way to implement it.

  • re: https://github.com/ocaml-multicore/eio/issues/577#issuecomment-1632321645 - this is currently worked around by checking every stream for present items and starting to wait while holding its mutex; if no stream has any items, all streams must have capacity (this is asserted). Maybe there is a hole in my logic, but it sounded fine in my head.
  • I had to modify the Waiters module slightly, which is what I had hoped to avoid by using multiple fibers previously. The way I modified it makes sense for this kind of application, but it could be that there is a race condition or logical trap I overlooked.
  • There are too many in-line comments explaining what the too-long function select_of_many does, but maybe it helps you while reviewing it :-)
  • Only Locking streams are handled at the moment, with an assert in place to enforce this. Mostly for the reason that I've wanted to get an initial implementation going before trying to handle everything.

Again, I'm not at all offended if a tighter implementation ends up replacing this PR, but my fingers were itching to try and implement it myself :-)

dermesser avatar Jul 12 '23 20:07 dermesser