Yes it is possible, but not with a single Thread
, since programs are sequences of instructions.
If I understand what you want, this is a simpler type of Produtor/Consumidor
problem (since I do not think I have a memory limitation). You will need to work with at least two threads
and a shared memory area (a vetor
, or lista
, etc. [will treat here as lista
]) between the two threads.
While thread produtora
reads the data from the terminal and stores it in lista
to thread consumidora
removes the next element from the list and performs the desired processing.
However, working with shared memory areas causes some problems, as in thread consumidora
tries to get an element and lista
is empty. To solve this problem you will have to use semáforos
, locks
and etc.
For a more in-depth study I suggest reading these articles.
This is a better understanding of the Producer and Consumer problem
link
This one for python thread synchronization mechanisms
link