Multithreading synchronization interview question: Find n words given m threads
Posted
by
rplusg
on Programmers
See other posts from Programmers
or by rplusg
Published on 2012-10-10T18:54:19Z
Indexed on
2012/10/10
21:52 UTC
Read the original article
Hit count: 275
I came across this question:
You are given a paragraph , which contain n number of words, you are given m threads. What you need to do is , each thread should print one word and give the control to next thread, this way each thread will keep on printing one word , in case last thread come, it should invoke the first thread. Printing will repeat until all the words are printed in paragraph. Finally all threads should exit gracefully. What kind of synchronization will use?
I strongly feel we cannot take any advantage of threads here but interviewer is trying to understand my synchronization skills?
No need of code, just put some thoughts. I will implement by myself.
© Programmers or respective owner