To use or not to use threads

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • myusernotyours
    New Member
    • Nov 2007
    • 188

    #1

    To use or not to use threads

    Hello people,

    I have to optimize a very slow C program that does some processing on some data from a Db, creating some xml files. It has to work with a fairly large data set and is quite slow.

    The original programmer used threads for this processing, putting items in input queues that the threads keep checking for, processing and passing to the next queue.

    There are other bottlenecks (aside from the threading model) but we are running about 8 threads and I am thinking that these threading may be unnecessary since:

    a) This is a batch process with no user interaction so it doesn't matter if we have a long running task.

    b) There is no task that has priority. The process is quite sequential.

    c) All the context switching probably slows things down a bit.


    Would it help to remove the threading from this program?

    Is it really helpful to use threads in such a sequentially processing batch program?

    Regards.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    If you only have 1 thread working at a time then the threading is not necessary.

    If however you have more than 1 thread working at a time and you are running on a multi-core processor then leave them in.

    If you really want to work out what is making the program run slowly rather than guessing properly profile the program and deal with the highlighted bottle necks.

    Context switching does inherently add some overhead but unless your threads are performing an excessive quantity of unrequired context switches this should not be that much of an issue.

    Threads are useful anywhere that they either increase performance or increase maintainability .

    Comment

    Working...