3 threads printing numbers of different range
Posted
by
user875036
on Programmers
See other posts from Programmers
or by user875036
Published on 2011-08-16T19:36:23Z
Indexed on
2012/11/04
11:23 UTC
Read the original article
Hit count: 147
multithreading
|concurrency
This question was asked in an Electronic Arts interview:
There are 3 threads. The first thread prints the numbers 1 to 10. The second thread prints the numbers 11 to 20. The third thread prints the numbers from from 21 to 30. Now, all three threads are running. The numbers are printed in an irregular order like 1, 11, 2, 21, 12 etc. If I want numbers to be printed in sorted order like 1, 2, 3, 4..., what should I do with these threads?
© Programmers or respective owner