This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I am trying to read data from an SD card. But the library function of read() is in blocking mode (synchronous). I want to modify this function into non-blocking mode (asynchronous) as it is waste of time waiting for the read operation to complete and I have to do other tasks as well. Its in C.
gajji sal wrote:Thank you for the reply. Can you please elaborate a bit
Your requirement is to do two things at the same time; read a card and continue processing. This implies you need two threads; in one you read the card and in the other you do whatever you want to do while waiting for the card to be read. You don't say what platform you are working on but I'm pretty certain that whatever it is there will be a version of 'pthreads' available. First check your C compiler library documentation and if that is not enough then use Google .
Multiple threads is indeed one way to do this, but it has significant implications regarding how your whole program is written. Another way to do this -- and probably still the most common way on Linux -- is to use asynchronous I/O. All operating systems have the notion of calling a function to initiate an I/O operation, and then later checking to see when it's done, or being notified when it's done. On UNIXy systems, it's called select() or pselect(). Here's a tutorial on how to use it. Here is an introduction to doing the same sort of thing on Windows.