Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Do we need to schedule threads to diff processors?

Do we need to schedule threads to diff processors?

Scheduled Pinned Locked Moved C#
helpquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Srinivas P N V
    wrote on last edited by
    #1

    Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini

    L S OriginalGriffO 3 Replies Last reply
    0
    • S Srinivas P N V

      Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Srinivas P N V wrote:

      Are those 25 threads run on single processor or all 4 logical processors?

      Whatever Windows chooses (and that may vary!) It's the OS that's responsible for scheduling threads.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      D 1 Reply Last reply
      0
      • S Srinivas P N V

        Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        if memory serves me correctly Task Class[^] and Parallel.ForEach[^] are optimised to handle the cores of a processor better than Threading class or threadpool. But you haven't really given much information to help us give you a better answer.

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        1 Reply Last reply
        0
        • S Srinivas P N V

          Hello, I had a machine with 4 logical processors(1 => physical processor, 2 => cores, 4 => logical processors). And I have implemented an application which can run with 25 threads. Now, if i run my application(with 25 threads) on my machine(with 4 logical processors), Are those 25 threads run on single processor or all 4 logical processors? Can any one help me please.. Thanks, Srini

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          One logical processor can run one thread at a time - and this includes all the of system threads, as well as all the application threads in the machine - not just yours. So at any one time, four threads can be running at the same time, and one or more of these may be one of your 25. The system is at liberty to start threads on any processor available to it at the time it wants to switch threads - either because a thread has paused itself, ot run out of time slice and must wait to give other threads a chance. You can't force a thread onto an processor, or even force a thread to run without interruption from beginning to end. So all 25 thread could run on the same processor, one after another, or they could be spread around - you have no influence over that, and cannot even tell which processor you are running on: or even if it was the same processor a microsecond ago! Do be aware that if you start a number of threads to speed things up, you may infact slow things down due to locking and thread switching overheads - particularly if there aren't enough physical processors to run them all at the same time.

          This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre. Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          T 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            One logical processor can run one thread at a time - and this includes all the of system threads, as well as all the application threads in the machine - not just yours. So at any one time, four threads can be running at the same time, and one or more of these may be one of your 25. The system is at liberty to start threads on any processor available to it at the time it wants to switch threads - either because a thread has paused itself, ot run out of time slice and must wait to give other threads a chance. You can't force a thread onto an processor, or even force a thread to run without interruption from beginning to end. So all 25 thread could run on the same processor, one after another, or they could be spread around - you have no influence over that, and cannot even tell which processor you are running on: or even if it was the same processor a microsecond ago! Do be aware that if you start a number of threads to speed things up, you may infact slow things down due to locking and thread switching overheads - particularly if there aren't enough physical processors to run them all at the same time.

            This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre. Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.

            T Offline
            T Offline
            TnTinMn
            wrote on last edited by
            #5

            Quote:

            You can't force a thread onto an processor,

            I'm not claiming any expertise on this subject and have no idea why one would wish to do this. But couldn't you iterate through Process.GetCurrentProcess.Threads seeking the ProcessThread which has the ID equal to the ID returned from the API function GetCurrentThreadId (called on the thread in question). Once you have the needed ProcessThread, you could set its processor affinity[^] property.

            L 1 Reply Last reply
            0
            • T TnTinMn

              Quote:

              You can't force a thread onto an processor,

              I'm not claiming any expertise on this subject and have no idea why one would wish to do this. But couldn't you iterate through Process.GetCurrentProcess.Threads seeking the ProcessThread which has the ID equal to the ID returned from the API function GetCurrentThreadId (called on the thread in question). Once you have the needed ProcessThread, you could set its processor affinity[^] property.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              TnTinMn wrote:

              I'm not claiming any expertise on this subject and have no idea why one would wish to do this.

              Attempting to improve performance, I'd guess. Still, Windows will halt the thread from time to time, and while one can set an affinity, one can not claim a specific core. that's a good thing

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              1 Reply Last reply
              0
              • L Lost User

                Srinivas P N V wrote:

                Are those 25 threads run on single processor or all 4 logical processors?

                Whatever Windows chooses (and that may vary!) It's the OS that's responsible for scheduling threads.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                D Offline
                D Offline
                Dholakiya Ankit
                wrote on last edited by
                #7

                Good one i see your link

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups