(console) Non blocking input

This is a discussion on (console) Non blocking input within the C++ Programming forums, part of the General Programming Boards category; I'm currently evaluating my options in terms of implementing a non-blocking input stream. I'm unsure as to what other options ...

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,467

    (console) Non blocking input

    I'm currently evaluating my options in terms of implementing a non-blocking input stream. I'm unsure as to what other options I may have available. The output stream needs to stay blocked.

    Requirements are portability across windows and linux. Mac would be nice too.
    Minimal conditional compilation is acceptable too. Although not desirable.

    My current options are:

    Boost::threads
    - Implement the input stream here, outside of the main thread. The only point of contact between both threads is a command queue. The input thread only pushes onto the queue. It doesn't manage it in any other way neither it concerns itself with the queue contents. The main thread listeners will pop the command queue and implement a sort of event-driven console application. However I do need the output stream on the main thread to block. So this does complicate thread management.

    Boost::asio - Maybe a little overkill for this. And I'm not even sure I can use it. However my program already depends on boost::asio.

    ncurses - using such functions as cbreak, halfdelay and nodelay, I can turn off the tty buffers and implement a non blocking input. My program already depends on ncurses for screen layout, so this becomes only a implementation decision. However this method is crude and complicates user input management.

    ...

    I'm biased towards threads. Seems the easiest and most solid solution. But if you know of a better way to implement non-blocking input/blocked output in a console, please let me know.
    Last edited by Mario F.; 08-23-2009 at 11:25 AM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 08:31 PM
  2. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  3. Console input
    By ozzy34 in forum C++ Programming
    Replies: 9
    Last Post: 05-14-2004, 12:05 PM
  4. How to put a Char into the Input buffer of a console?
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 03-09-2003, 09:05 AM
  5. Need help with Console Keyboard Input
    By pawelx2 in forum Game Programming
    Replies: 5
    Last Post: 05-30-2002, 11:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21