The last thread only processes a single iteration and then breaks, because the eof-Flag is not reset to 0 along with word_count, last_word_count and sentence_length at the end of each iteration.
eof = 0 needs to be added in the codeblock beginning in line 419 and ending in line 426.