Multithreading synchronization interview question: Find n words given m threads
- by rplusg
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.