Paul Clapham wrote:Actually no, I don't get your point. What exactly are you trying to do?
And when I ask that question, I'm not asking about that business about loops. I'm asking about this:
I need a waiting loop.
What's a "waiting loop"? And if you had one of them, what would you be using it for? In other words, what is the problem to which this "waiting loop" is the answer?
I was worried whether it was the right expression :)
Well, I mean a piece of a code that causes a delay in thread execution. An example:
When two or more threads execute this, the first thread executes the first iteration but because it is fast, it executes even the second iteration, the third and so on. The second thread doesn't get a chance because the first thread is too fast.
In this case, the input looks like this:
Thread-0 writes number: 0
Thread-0 writes number: 1
Thread-0 writes number: 2
Thread-0 writes number: 3
.
.
.
So, I can add a piece of a code that delays the first thread so that the second thread can execute the following iteration:
The input looks like this:
Thread-0 writes number: 0
Thread-1 writes number: 1
Thread-0 writes number: 2
Thread-1 writes number: 3
.
.
.
This solves the problem but it just doesn't look like the best solution, there has to be something better.
I hope it is more comprehensible :|