Re: Waiting on multiple blocking events
Yang Zhang <[email protected]> Mon, 01 Dec 2008 13:34:03 -0500
| Newsgroups | gmane.comp.lib.state-threads.user |
|---|---|
| Message-ID | <[email protected]> |
Mike Abbott wrote:
>> Is there a way to "compose" together multiple blocking operations?
>
> Sounds interesting, kinda like what kqueue()/kevent() do: one-stop
> event processing. "Block this thread until one of this laundry list of
> disparate events fires." Do you have a prototype implementation you'd
> like to contribute to the project, or wrappers you'd contribute to its
> "extensions" library?
I have a poor man's implementation of "cleanly interruptible points."
This involves primitives called "hubs" (sets of threads) that threads
may join and other threads may signal. It's similar to a condition
variable, but signaling results in interrupting the thread from its
current blocking operation.
{
st_intr intr(hub);
int ret = st_read_fully(...);
if (ret == EINT) ...
...
}
This turned out to be suitable enough for my purposes. The code is all
available in my little header of ST tools:
http://assorted.svn.sf.net/viewvc/assorted/cpp-commons/trunk/src/commons/st/st.h?revision=1077&view=markup
I thought about my more general suggestion some more. You can implement
any() atop ST by starting a thread for each blocking operation involved
in the any(), wrapping them in functions that - on finishing - interrupt
the other threads (using something similar to the above mechanism, on a
hub created locally by the any() call), informing them that they're the
losers (so that they may properly react/clean up), and also notifying
the parent thread of its own success and return value.
>
>
>
> -------------------------------------------------------------------------
> 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=/
> _______________________________________________
> State-threads-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/state-threads-users
--
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=/