Results 1 to 9 of 9

Thread: Is running multiple threads faster then a single thread on a single core cpu?

  1. #1

    Thread Starter
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Is running multiple threads faster then a single thread on a single core cpu?

    Hi all,

    Say I have a code with 3 methods that do some pretty intensive work. Would executing these methods on 3 seperate threads be faster then executing them one after the other on a single core cpu? And what if it's a dual core or HT?

    Thnx in advance for your replies.

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    On a single core I'm pretty sure it would take at least the same time, if not longer. All that's happening is that the CPU is switching between the three threads every x milliseconds. A single core CPU cannot run three threads simultaneously. It could even take longer because the switch between threads takes a little time too.
    At least, this is my understanding of the lowest level of multithreading. Perhaps VB.NET handles it differently, but I would be quite surprised if it was faster to use threads.

    On a multi-core CPU however, each core should, in theory, be able to run it's own set of threads, so you could run two threads on one core and the third on the other core, then it should be faster. I'm not sure how you can choose which core to run a thread on though, and I'm pretty sure the OS decides that, so I dunno if that works in practice.

  3. #3

    Thread Starter
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    Thanks for your reply. That's exactly what I was thinking.

    I think you can create multicore apps in .Net 4.0 but not in 3.5 .

    [EDIT]
    I think you are right in saying the OS decides on which core it runs a thread. So you probaly need a very very intensive operation before it will use the 2nd core. As far as I know, most dual core cpu's these days turn the 2nd core off most of the time to make it more energy efficient.
    Last edited by gonzalioz; Dec 23rd, 2009 at 10:19 AM.

  4. #4
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    You can create multicore apps in .Net 1.0 (VS 2002)

    In .Net 2.0+ I use the BackgroundWorker as it provides events for everything I need to do so I haven't manually done threading like I used to in VS 2003 in quite a while now.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    .NET 4.0 adds parallel extensions that make it easier to perform certain tasks in parallel rather than serially. Most specifically, you can perform multiple iterations of a For or For Each loop simultaneously with essentially no extra code. That doesn't make it more multi-threaded than previous versions though, where you could do the same but it would require extra code.

    Whether or not multiple threads would run faster on a single core would depend on exactly what work is being done. Remember that your app is sharing time with other processes anyway.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    As far as I know, most dual core cpu's these days turn the 2nd core off most of the time to make it more energy efficient.
    I've never heard of that and when I look at task manager on my quad core PC it shows all 4 cores as being quite active. I'm pretty sure that all of the cores get used pretty much all of the time.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    Quote Originally Posted by gonzalioz View Post
    As far as I know, most dual core cpu's these days turn the 2nd core off most of the time to make it more energy efficient.
    Most of the time? Maybe laptops would shut down a core to save power but certainly not most of the time and desktop systems probably not much at all.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    Quote Originally Posted by jmcilhinney View Post
    .NET 4.0 adds parallel extensions that make it easier to perform certain tasks in parallel rather than serially. Most specifically, you can perform multiple iterations of a For or For Each loop simultaneously with essentially no extra code. That doesn't make it more multi-threaded than previous versions though, where you could do the same but it would require extra code.

    Whether or not multiple threads would run faster on a single core would depend on exactly what work is being done. Remember that your app is sharing time with other processes anyway.
    I thought that parallel extensions were available since 3.5. At least that's what I got from this article.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Is running multiple threads faster then a single thread on a single core cpu?

    Quote Originally Posted by weirddemon View Post
    I thought that parallel extensions were available since 3.5. At least that's what I got from this article.
    The parallel extensions are not a standard part of .NET 3.5 SP1. There is a separate download that will work with .NET 3.5 SP1, although it's unsupported by Microsoft. The parallel extensions will be a standard part of .NET 4.0 when it's released.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width