Waiting on multiple blocking events
Yang Zhang <[email protected]> Tue, 25 Nov 2008 17:32:12 -0500
| Newsgroups | gmane.comp.lib.state-threads.user |
|---|---|
| Message-ID | <[email protected]> |
Is there a way to "compose" together multiple blocking operations? E.g., for the following blocking operations: st_read_fully(...) st_read_fully(...) st_thread_join(...) st_cond_wait(...) st_sleep(...) I'd like to be able to: - wait for all of them to finish - wait for any one of them to finish The former is easy - spawn a thread per operation and join on all of them (in any order). The latter is tricky. It becomes especially so if you want to guarantee that *exactly* one of them successfully completes. A two-phase commit must take place to select a winner and to have the loser clean up after itself (e.g. so the read operations do not simply drop incoming data). Such composition would be powerful. E.g., being able to compose with st_sleep(...) would render timeout parameters unnecessary. Again, if I were to build my own API atop ST, then as long as the user only uses my API and not ST directly, then I can write the rules. However, I'm wondering if there's a simpler approach (less work), esp. one that allows ST to continue to be used. The following is a Python implementation of this idea, using Python 2.5 generators: svn://scripts.mit.edu:36900/mit/golem/Share/svn/af -- Yang Zhang http://www.mit.edu/~y_z/ ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/