Simulate qui thread in console app and recieve signals - Unix

This is a discussion on Simulate qui thread in console app and recieve signals - Unix ; Hi there, i would like to do console application, and after execution it would create a thread, while in the main one it would read one character from std input, and if it would be equal 'q', it would quit. ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Simulate qui thread in console app and recieve signals

  1. Simulate qui thread in console app and recieve signals

    Hi there,

    i would like to do console application, and after execution it would
    create a thread, while in the main one it would read one character
    from std input, and if it would be equal 'q', it would quit. I would
    like also it to be able to break stdin reading loop, when other thread
    send some signal to the main thread. I don't know if it is possible?
    For example the newly created thread could make some kind of a
    descriptor (i don't know if pipes are applicable here...)and the main
    thread would make select on this descriptor and stdin descriptor in
    the loop. Maybe signals?? - but i don't know what is happening when
    other thread send signal to its process (or even if it is possible...)
    and how to break reading from std input then? Thansk for all your
    replies.

    Best,

    Przemek


  2. Re: Simulate qui thread in console app and recieve signals

    On 15 Aug, 14:52, Bronson wrote:

    > i would like to do console application, and after execution it would
    > create a thread, while in the main one it would read one character
    > from std input, and if it would be equal 'q', it would quit. I would
    > like also it to be able to break stdin reading loop, when other thread
    > send some signal to the main thread. I don't know if it is possible?
    > For example the newly created thread could make some kind of a
    > descriptor (i don't know if pipes are applicable here...)and the main
    > thread would make select on this descriptor and stdin descriptor in
    > the loop.


    The main thread can wait for events on several file descriptors using
    select() (http://en.wikipedia.org/wiki/Event_loop#File_interface).

    One of the file descriptors can be STDIN_FILENO (stdin), the other
    descriptor can be the read end of a pipe (see man pipe) or a unix
    local socket (unix datagram socket is the simplest, see man
    socketpair). The other thread can use that datagram socket to
    communicate messages to the main thread. The select() call returns
    when any of these file descriptors become ready for reading, so that
    waiting on stdin does not block receiving messages from the other
    thread.


+ Reply to Thread