1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

First Crack at Multithreaded Programming

  1. Mar 4, 2013 #1
    1. The problem statement, all variables and given/known data

    Create a multithreaded program (Java) that finds a word in a text file and reports the lines one which the word appeared. Word lines should be reported in the order in which they appear.

    2. Relevant equations



    3. The attempt at a solution

    I know that I can just start up a bunch of threads to run over different parts of the text file,, but that gives the potential that the lines are going to be returned in all sorts of messy errors. Any suggestions or help materials that could help me preserve the order of the returns while also managing to increase speed over the single-threaded program?
     
  2. jcsd
  3. Mar 5, 2013 #2

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    You can give each thread a small part of the text, so all threads run over "some fraction of the first n% of the text" in parallel. Collect the results, sort them*, print them, continue with the next n% of the text (can be done in parallel to the sorting of course).

    *trivial with a good line distribution
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: First Crack at Multithreaded Programming
  1. Fatigue Cracks (Replies: 1)

  2. Multithreaded File IO (Replies: 7)

Loading...