How to increse the speed of program using multithreading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Man4ish
    New Member
    • Mar 2008
    • 151

    How to increse the speed of program using multithreading

    How can we speed up the program using multithreading in C++.

    Manish
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    No it is impossible, by definition multi-threading adds more work for the processor to do, it now has to control scheduling the different threads.

    You use multi-threading to allow you to run 2 threads of execution that have little or nothing to do with each other asynchronously so that you can write the code of each thread without having to worry about what the other thread is doing. Not to speed up the program.


    Hmmm, well actually I guess with modern multi-core processors you may be able to get a speed increase. However I have a feeling that by default Windows runs all the threads of a single process on the same processor. But that is a guess I am not sure and I have absolutely no idea what happens on Linux.

    Comment

    • Man4ish
      New Member
      • Mar 2008
      • 151

      #3
      Originally posted by Banfa
      No it is impossible, by definition multi-threading adds more work for the processor to do, it now has to control scheduling the different threads.

      You use multi-threading to allow you to run 2 threads of execution that have little or nothing to do with each other asynchronously so that you can write the code of each thread without having to worry about what the other thread is doing. Not to speed up the program.


      Hmmm, well actually I guess with modern multi-core processors you may be able to get a speed increase. However I have a feeling that by default Windows runs all the threads of a single process on the same processor. But that is a guess I am not sure and I have absolutely no idea what happens on Linux.
      How can we do multi threading for running multiple tasks .

      Manish Gupta

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Man4ish
        How can we do multi threading for running multiple tasks .

        Manish Gupta
        Start a thread for each available task and run your threads.

        kind regards,

        Jos

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          Originally posted by Man4ish
          How can we do multi threading for running multiple tasks .
          Writing thread-safe code takes discipline. You need to decide which variables should be local to each thread and which should be shared in common by all the threads. Then you need to implement your code such that it correctly implements those variable scope decisions. You need to design strategies to protect all the common variables so that simultaneous access from multiple threads doesn't cause problems.

          Comment

          Working...