Applying Threading to Existing software

This is a discussion on Applying Threading to Existing software within the C Programming forums, part of the General Programming Boards category; Is it possible to take existing code, which is not set up for multi-threading and write my own code that ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    47

    Applying Threading to Existing software

    Is it possible to take existing code, which is not set up for multi-threading and write my own code that basically applies the concept.

    Say I have a program that is going to generate a predermined amount of objects and manipulate them in sequential order (one after the other), dragging out runtime.

    Code:
    for(i=0;i=NUM_OBJECT;i++)
    {
        //generate object
        //manipulate it
        //let's say it takes a couple minutes before the next iteration occurs
    }
    Is it possible to just implement my own code which would basically thread the process of generating an object and manipulate it, so the loop could just start the process of the next object instantly, and so forth...? Essentially trick the program to thinking that "oh i'm done with this object, start the next" even though that object is being processed by a thread...

    Above is basic, the software is much more complicated but what i've explained is the basic concept. I just want to create threads to handle the object stuff so instead of it following a linear pattern, they will all be generating and manipulated simultaneously....

    Also, the average machine running an application is Quad Core (~2.5ghz x 4), 4gb of RAM...., also furthering the concept to distribute over a newtwork would be very handy too.

    Re-writing the software will be painstaking and I would much rather implement a solution to work with the existing code.

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Multhithreaded programming is non-trivial to get right if you just wrap code-blocks in thread code. Can you do it? Yeeees but unless the threaded code owns ALL of the resources it needs you need to think about things like synchronization (mutexes) and IPC (InterProcess Communication) a la semaphore.

    Distributed brings a whole new set of issues to the table and that will probably call for a 50-70 percent rewrite...

    Sorry, I know this is not what you wanted but the only easy thing about getting a single-threaded app to work right an a multithreaded app, let alone a distributed app is getting it wrong.

    Jeff

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    47
    What about if i am creating seperate object instances, passing them off to threads to be created and manipulated?

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875

    Multithreading a single-threaded application

    The key thing is anything allocated should be done before launching the thread and there can be NO shared resources and they can call NO external functions that are not fully re-entrant. W/O knowing more about the source app this is the best advice I can give. It has been my experience that single-threaded code stuffed into a multithread framework is a lot more problematic than it first appears. Also almost without exception apps that are designed with multithreading in mind work better and more importantly, less buggy that single-threaded code that has been refactored to be MT...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Software Design/Test - Redmond, WA
    By IRVolt in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 06-11-2008, 10:26 AM
  2. cout << SunTradingLLC << "is looking for C++ Software Developers" << endl;
    By sun trading in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 04-02-2008, 11:48 AM
  3. Why C Matters
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 136
    Last Post: 01-16-2008, 08:09 AM
  4. Adding trial period to software
    By BobS0327 in forum C Programming
    Replies: 17
    Last Post: 01-03-2006, 01:13 PM
  5. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21