14 lines
841 B
Markdown
14 lines
841 B
Markdown
|
The first usecase we are going to take a look at, is about the queue.
|
||
|
There are trivial ones like a playlist, where you can add more music to.
|
||
|
Another common usecase is the breadth first search for a tree traversal.
|
||
|
But we are going to look at a more general concept.
|
||
|
|
||
|
Imagine you have some code, which produces some data and another part, which
|
||
|
processes the data. This doesn't necessarily have to be in sync.
|
||
|
Specially when you talk about different threads or processes.
|
||
|
You then need a way to buffer the incomming data, otherwise you would
|
||
|
overwrite the oldes one, which, depending on the circumstances, can lead to errors.
|
||
|
A queue helps to get around this problem.
|
||
|
|
||
|
For this exercise we prepared a thread, which just produces some random numbers and pushes them on a queue.
|
||
|
Your task is to add the oldest two together and print them out.
|