Thread: automatic parallelizing of 2 threads in a dual core ??

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251

    automatic parallelizing of 2 threads in a dual core ??

    If I write a multithread program with pthreads on a Linux platform, do I have to expect threads run parallel on the two cores automatically (of course as long as there are not threads waiting for others or for events like I/O) or is there some probability that they run on one core only unless I use some directive or whatever??

    Thank you

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    They will run on both threads unless there are other threads that want to run at the same time. Which thread ends up on which core and how long they stay that way is entirely random.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    Quote Originally Posted by matsp View Post
    They will run on both threads unless there are other threads that want to run at the same time. Which thread ends up on which core and how long they stay that way is entirely random.

    --
    Mats
    ok so if in the system i know that most CPU is used by my program and I manage to split the most of the job in at least 2 threads I can expect time elapsed to decrease close to 1/2 ?
    (considering no false sharing and so on)

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, if your two threads are mostly CPU bound, and not dependant on each other, then half the time or close to that is what you can expect.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    thank you very much!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Swapping for XP on dual core...
    By Else in forum Tech Board
    Replies: 18
    Last Post: 01-01-2009, 10:07 AM
  2. Replies: 5
    Last Post: 10-17-2008, 11:28 AM
  3. Graphic problems with Dual Core processors
    By BrownB in forum Tech Board
    Replies: 3
    Last Post: 11-07-2006, 05:10 AM
  4. buying a laptop ; intel dual core?
    By BobMcGee123 in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 07-30-2006, 02:28 PM
  5. Dual Core CPUs
    By (TNT) in forum Tech Board
    Replies: 4
    Last Post: 12-27-2005, 10:18 AM