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. Threads

Threads

Scheduled Pinned Locked Moved C#
csharphelpquestion
9 Posts 5 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.
  • P Offline
    P Offline
    P T R K
    wrote on last edited by
    #1

    Hi Friends, Is possible to run 500 threads per second using c#? Please help me Thanks in advance

    L H 2 Replies Last reply
    0
    • P P T R K

      Hi Friends, Is possible to run 500 threads per second using c#? Please help me Thanks in advance

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      C# would not be the limiting factor. Windows could probably cope; a server version would for sure. But I haven't encountered any application yet where it would make sense to have that many threads in a single process. It would be a huge waste of cycles (thread switches are expensive), bytes (each thread has its context, where the stack is the biggest chunck), and time (your cache efficiency goes down as the fixed size caches are used by more threads now). Here is my rule of thumb in multi-threading: For most apps, it does not pay to have similar code in more than 1*N to 2*N threads where N is the number of processors. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
      [The QA section does it automatically now, I hope we soon get it on regular forums as well]


      P H 2 Replies Last reply
      0
      • L Luc Pattyn

        C# would not be the limiting factor. Windows could probably cope; a server version would for sure. But I haven't encountered any application yet where it would make sense to have that many threads in a single process. It would be a huge waste of cycles (thread switches are expensive), bytes (each thread has its context, where the stack is the biggest chunck), and time (your cache efficiency goes down as the fixed size caches are used by more threads now). Here is my rule of thumb in multi-threading: For most apps, it does not pay to have similar code in more than 1*N to 2*N threads where N is the number of processors. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
        [The QA section does it automatically now, I hope we soon get it on regular forums as well]


        P Offline
        P Offline
        P T R K
        wrote on last edited by
        #3

        Thank you your reply. Is there any example to use multi threading (Asynchornous and thread pool) in C# window service application?

        A 1 Reply Last reply
        0
        • P P T R K

          Thank you your reply. Is there any example to use multi threading (Asynchornous and thread pool) in C# window service application?

          A Offline
          A Offline
          Abhinav S
          wrote on last edited by
          #4

          Does this[^] help?

          Now...bring me that horizon. And really bad eggs...Drink up me hearties, YO HO!

          1 Reply Last reply
          0
          • L Luc Pattyn

            C# would not be the limiting factor. Windows could probably cope; a server version would for sure. But I haven't encountered any application yet where it would make sense to have that many threads in a single process. It would be a huge waste of cycles (thread switches are expensive), bytes (each thread has its context, where the stack is the biggest chunck), and time (your cache efficiency goes down as the fixed size caches are used by more threads now). Here is my rule of thumb in multi-threading: For most apps, it does not pay to have similar code in more than 1*N to 2*N threads where N is the number of processors. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
            [The QA section does it automatically now, I hope we soon get it on regular forums as well]


            H Offline
            H Offline
            Harvey Saayman
            wrote on last edited by
            #5

            Luc Pattyn wrote:

            have similar code in more than 1*N to 2*N threads

            My rule of thumb is 1.5*N :thumbsup:

            Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

            L M 2 Replies Last reply
            0
            • P P T R K

              Hi Friends, Is possible to run 500 threads per second using c#? Please help me Thanks in advance

              H Offline
              H Offline
              Harvey Saayman
              wrote on last edited by
              #6

              Theoretically, yes... you can have unlimited threads. But in practice, not so much As Luc pointed out 500 threads are a bit heavy. If their running similar code I'd use Smart Thread Pool[^] Its easy to use, quite flexible and to quote JSOP, "It simply works" :cool:

              Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

              1 Reply Last reply
              0
              • H Harvey Saayman

                Luc Pattyn wrote:

                have similar code in more than 1*N to 2*N threads

                My rule of thumb is 1.5*N :thumbsup:

                Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Harvey Saayman wrote:

                1.5*N

                you may run into trouble on an AMD triple core... :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
                [The QA section does it automatically now, I hope we soon get it on regular forums as well]


                H 1 Reply Last reply
                0
                • L Luc Pattyn

                  Harvey Saayman wrote:

                  1.5*N

                  you may run into trouble on an AMD triple core... :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
                  [The QA section does it automatically now, I hope we soon get it on regular forums as well]


                  H Offline
                  H Offline
                  Harvey Saayman
                  wrote on last edited by
                  #8

                  Even on single core dinosaurs... I was thinking that same thing just after clicking post on my OP :rolleyes:

                  Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                  1 Reply Last reply
                  0
                  • H Harvey Saayman

                    Luc Pattyn wrote:

                    have similar code in more than 1*N to 2*N threads

                    My rule of thumb is 1.5*N :thumbsup:

                    Harvey Saayman - South Africa Software Developer .Net, C#, SQL you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                    M Offline
                    M Offline
                    Matty22
                    wrote on last edited by
                    #9

                    Having rules of thumb like 2* number of processors is a totally pointless affair. Consider the following scenario --I want to wait on 70 blocking operations --When one of these operations complete. I would like a response/somethingto happen, quickly (Low latency) I could *Have 2*2 processors threads constantly polling all 70 blocking operations every millisecond to see when they are done. This would waste lots of CPU *Use 70 threads which are all in Wait mode which would consume very little CPU Using 70 threads would be far better in this case The number of threads you need has nothing to do with the number of CPUs. And everything to do with latency and how much blocking operations you need to wait on

                    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