A
A
asurkis2016-07-19 16:55:14
C++ / C#
asurkis, 2016-07-19 16:55:14

How to enter data from the console without blocking the thread?

I have a graphical application in C++, it has a main loop (reading and processing events, drawing graphics through OpenGL, etc.), but it also requires input from the console
. Is it possible to do this without creating an additional thread?
At the same time, the current thread should not "hang" and wait for the end of the input, since, as already indicated, GUI processing takes place in it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2016-07-19
@asurkis

It is better to make a separate thread. Otherwise, you will have to cycle the task manager from the OS.

P
polar_winter, 2016-07-20
@polar_winter

Stream (stream) input - the same file descriptor only its number is known in advance. Use asynchronous reading (asynchronous input - output), such as select system calls, poll, aio_read, boost::asio, etc. etc. As noted by Aryan radio - an alternative approach with blocking calls and threads (thread) - is more common, and easier to accept by most programmers, than a state machine city for processing concurrent tasks in a single thread. But if a framework like Qt did it for you (created an event loop, ...), then working in an event-driven model would be even easier than with threads. For example, asynchronous reading tied to a timer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question