Results 1 to 2 of 2

Thread: Single Threaded to Multithreaded: What's involved?

  1. #1
    Xtreme Legend
    Join Date
    Mar 2008
    Plymouth (UK)

    Single Threaded to Multithreaded: What's involved?

    This question is posed to fill a gap in my understanding of "How things work"

    I wonder if anyone can tell me, or link me to a good explanation, about what is involved in converting a program to run multi-threaded.

    I also wonder about the efficiencies of doing such.

    I know SQRT(0) about programming so just a general view about the complexity is what I seek.

    My Biggest Fear Is When I die, My Wife Sells All My Stuff For What I Told Her I Paid For It.
    79 SB threads and 32 IB Threads across 4 rigs 111 threads Crunching!!

  2. #2
    Xtreme Addict
    Join Date
    Mar 2010
    Since I'm not an expert and my English might be an issue when trying to explain technical details, I'll point you to other people's comments so you can have a general idea.

    Let's start with this explanation by gamerk316 here:

    Quote Originally Posted by gamerk316
    I'll try and dumb it down a bit:

    CPU: The "brains" of the computer. Responsable for all computations, loading of data, etc

    Core: An individual CPU unit. For instance, a Dual Core CPU can be thought of as having two seperate CPU's in a single package, with their own dedicated registers and cache. [This isn't entirely correct, but its a simlified explanation]

    Process: A process can be thought of as a program. When you start a program, it kicks of its process, and all memory that is allocated is allocated at the process level.

    Thread: A thread is a unit of execution within a process. One process can have many threads. For instance, you could have a thread to handle User Input, a thread for program control, a few threads for AI managment, a thread for audio, etc. All these threads exist within a single process.

    Within most modern OS's, the thread is the smallest unit of execution; the OS schedules threads [usually based on priority], and the CPU spends some time operating on a thread, before swapping in a new one to work on [giving the illusion multiple things can happen at the same time].

    On a multiple-CPU or multi-core system, multiple threads could be run at the same time, hence why there is an increasing focus on software parallelization.
    This is a good explanation because it clarifies the true meaning of thread vs the popular meaning of thread=logic core.
    Once you have understood this concept, you may wonder where is the problem when splitting the threads that form a program across several cores.
    The problem is thread sync. When you run a program on a single core, you can have each thread executed in a certain order. This way you make sure that each thread has all the information it needs to run when it's its turn to run. Random example: when in a game, you might want to run something like:

    draw graphics
    read user input
    have the IA response to user's input

    That "read user input" step is not correct because normally input is handled in a different way but anyway.

    As you can see, each step is executed right after the previous one. The term "multithreading" refers to spread the threads so each thread runs on it's own core, if possible.

    I would suggest you now to read this:
    Have a look at the comments, some of them are an useful reading.

    Once you have an idea about the problems of thread syncing, you might want to read this:

    I hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts