Say I'm working with a system that allows async, nonblocking operations. If I queue up a set of those operations and specify their result buffer references:
nonblocking_write( message, write_buffer ); nonblocking_read( source, read_buffer ); nonblocking_read( other_source, other_read_buffer ); wait(); // do stuff with results now in the buffers
or queue up the same set of operations, but specify result callbacks to do stuff with results directly
nonblocking_write( message, write_handler ); nonblocking_read( source, read_handler ); nonblocking_read( other_source, other_read_handler ); // doing stuff happens in the result handlers, not here
My question is about the library or environment exposing the
nonblocking_*() operations. What software structures and patterns allow this kind of thing to happen?
These are my thoughts so far:
In a multithreaded environment, spawn a new thread within the nonblocking operation, then run an equivalent blocking operation within that thread.
In a single threaded environment, define an
tasksthat handle 'events', then have nonblocking operations push