• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Non-Blocking read() in C

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

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.

Any tips and ideas on how to do it.

Thank you in advance
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gajji sal wrote:
Any tips and ideas on how to do it.


Read the card in a separate thread.
 
gajji sal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the reply. Can you please elaborate a bit
 
Richard Tookey
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 .

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic