One thread waiting on multiple events?
Posted: Fri Dec 21, 2012 1:39 am
I've been hacking along on an application, and I'm trying to reduce the number of threads to cut down on the per-thread stack RAM use. My application has a somewhat complex state machine at the core. At present, I have multiple tasks using the state machine protected with a mutex to ensure one trip through at a time. I may have timers fire, a message arriving on a serial interface or two.
What I'm wondering is if there's some idiom that I'm not aware of, or technique to have one thread asleep, waiting for some of these other things to occur. In particular, I'd like to start a read on a serial channel to read some number of bytes, and then notify me asynchronously. At present, I do a "blocking" read using chIOReadTime(). Likewise, I might have a timer expire or a message arrive from another thread using a mailbox that I'd want to process and then run though my state machine.
Is there an example I should look at to get a sense of mechanism that might work for me? Certainly the low level primitive are undoubtedly in there, but I'd like to make sure I'm using the primitives in the way intended.
Thanks for any pointers!
What I'm wondering is if there's some idiom that I'm not aware of, or technique to have one thread asleep, waiting for some of these other things to occur. In particular, I'd like to start a read on a serial channel to read some number of bytes, and then notify me asynchronously. At present, I do a "blocking" read using chIOReadTime(). Likewise, I might have a timer expire or a message arrive from another thread using a mailbox that I'd want to process and then run though my state machine.
Is there an example I should look at to get a sense of mechanism that might work for me? Certainly the low level primitive are undoubtedly in there, but I'd like to make sure I'm using the primitives in the way intended.
Thanks for any pointers!