No announcement yet.

General ? about threading

  • Filter
  • Time
  • Show
Clear All
new posts

  • General ? about threading

    I've recently been musing about possible optimizations for
    my calculations code using threads. I have never used this
    feature before.

    If I had a structure like so:

    FOR LoopValue& = 1 TO NumIterations&
       CalculateStuffFor LoopValue&
    could I expect a performance increase if I converted it to call
    a threaded procedure for each loop value? To my mind, it would
    in effect be processing each loop value in parallel vs. serial,
    but I am not sure how Windows would handle the time slicing and if
    it would actually be of any benefit.

    I hesitate to experiment with my stable code right now to find out.
    Could anyone shed any light on this for me?

    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

  • #2
    Bern --

    I don't think you would improve your program's performance by doing that, at least not on a single-processor system. The overhead that would be required to obtain the results from the threads would outweigh the benefits, if there were any benefits to begin with.

    Remember, in a single-CPU system you only have so many CPU clock ticks to work with. If you run 100 different programs at the same time, they will each receive (at most) 1/100 of the processor's attention. And the same thing is true about threads. Each thread that you create will receive only a fraction of the CPUs processing time, and it will reduce the amount of time that is available to other programs/threads.

    Multi-threading is more useful if your calculations are very time-consuming, and you want the user to be able to continue working while it runs. For example, you might have an app that allows a user to compose an email message. If you launch a new thread to perform the "Send" operation, the user won't have to wait and they can begin composing their next message while the first one goes out "in the background".

    Or if your program needs to do two things at once, like maintaining a message loop for a GUI while monitoring a serial port for input. That would be a good use for threads.


    -- Eric

    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>
    "Not my circus, not my monkeys."


    • #3
      Thanks Eric,

      That's what I was thinking, but I wasn't sure.

      Bernard Ertl
      Bernard Ertl
      InterPlan Systems