I have a Linux process that needs to read from, say, the keyboard and mouse. It needs to do this asynchronously while also doing some main process.
The implementation I've come up with is to have the main process in one thread, and have two separate threads always read()ing from the keyboard and mouse. If Linux read() is blocking, will the keyboard and mouse threads become blocked while the main thread continues executing (what I want), or will the entire process become blocked?
All threads in a process will not block as a result of one or more threads in the process becoming blocked. Each thread will be scheduled if it is able to run, within the rules of the scheduler in effect.
So your design is quite valid. Just use proper synchronization techniques if the data you read has to be consumed by another thread. Semaphores and message queues are handy for that purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With