Tech Off Thread

15 posts

.NET in a multi-core processor world?

Back to Forum: Tech Off
  • User profile image
    Klaus Enevoldsen

    Hi,

    I read somewhere that Intel is planning a processor with 80 cores, wow! The current processors have 2 cores and soon we will have 4 cores available.

    As I understand it, a process in Windows runs on one core in the processor, a process can have multiple threads. Each thread is given time to process in the processor core in a round robin or something like that.

    I have a situation where I need a program to do 3 different things, now I perform them one at a time, but would it be better to start up each of the actions in its own thread? Would it result in better usage of the different cores to do the work quicker?

    If not, what should I then do? Start up multiple processes? - That does not seem natural.

    Just a thought.

    /Klaus Enevoldsen

  • User profile image
    littleguru

    I have read somewhere that parallelising problems does only help at a certain amount.

    When parallelising a problem to much you get so much overhead in checking how to synchronize all your "agents"/threads/... that all the benefit gets lost.

    80 cores is a lot. I wonder how all of them could be leveraged in a good way.

  • User profile image
    Sven Groot

    Klaus Enevoldsen wrote:
    As I understand it, a process in Windows runs on one core in the processor, a process can have multiple threads. Each thread is given time to process in the processor core in a round robin or something like that.

    I don't know where you heard that but it's wrong. Multiple threads in a single process can and will take advantage of multiple CPUs/cores.

  • User profile image
    Secret​Software

    Sven Groot wrote:
    
    Klaus Enevoldsen wrote:As I understand it, a process in Windows runs on one core in the processor, a process can have multiple threads. Each thread is given time to process in the processor core in a round robin or something like that.

    I don't know where you heard that but it's wrong. Multiple threads in a single process can and will take advantage of multiple CPUs/cores.


    Agreed. Each thread will be assigned to the available core. Having multiple cores means that more threads will be processed, and that the processor has more capacity to process more threads, who ever their owner is.  When you write multi-threaded, and Asynchronous applications you automatically take advantage of multi-core processing, because now the threads are not competing for a single core, but for 2 cores, and the more cores the better, it will mean the capacity to process 80+ threads at a time is a plus in terms of performance.

  • User profile image
    tomkirbygre​en

    I suggest you read the chapter on Processes, Threads and AppDomains in Joe Duffy's book. Joe has a second book on concurrency in the pipe - but in the mean time Joe's first book has a pretty good treatment on the subject.

    If you're into all things concurrent I'd strongly suggest Joe's blog:

    http://www.bluebytesoftware.com/blog/

    In many ways Joe's blog is shaping up to be the spiritual successor to Chris Brumme's CLR blog-of-legend.

  • User profile image
    Klaus Enevoldsen

    Great! Thanks for the advice and the blog link.

    I was not convinced that what I heard was true, so it is great with a clarification. Wink

    This means that every time a program is doing something that could be done concurrently one should always start different threads (unless all threads depends on the same resources e.g. IO).

    I think there is too little focus on these things, today I will use background worker 4 times! Big Smile

  • User profile image
    AndyC

    Klaus Enevoldsen wrote:
    

    This means that every time a program is doing something that could be done concurrently one should always start different threads (unless all threads depends on the same resources e.g. IO)



    Not quite. There is some overhead in spawning a thread so doing it for short lived tasks may be inefficient. Also, creating too many threads may degrade performance.

  • User profile image
    DigitalDud

    AndyC wrote:
    
    Klaus Enevoldsen wrote: 

    This means that every time a program is doing something that could be done concurrently one should always start different threads (unless all threads depends on the same resources e.g. IO)



    Not quite. There is some overhead in spawning a thread so doing it for short lived tasks may be inefficient. Also, creating too many threads may degrade performance.



    If you need to thread a whole bunch of short-lived tasks you should consider using the thread pool.

  • User profile image
    Klaus Enevoldsen

    So a rule/guideline would be to create new threads for concurrent tasks that potentially run for a long time? How long time is a long time? > 1 second?

  • User profile image
    littleguru

    SecretSoftware wrote:
    
    Sven Groot wrote: 
    Klaus Enevoldsen wrote: As I understand it, a process in Windows runs on one core in the processor, a process can have multiple threads. Each thread is given time to process in the processor core in a round robin or something like that.

    I don't know where you heard that but it's wrong. Multiple threads in a single process can and will take advantage of multiple CPUs/cores.


    Agreed. Each thread will be assigned to the available core. Having multiple cores means that more threads will be processed, and that the processor has more capacity to process more threads, who ever their owner is.  When you write multi-threaded, and Asynchronous applications you automatically take advantage of multi-core processing, because now the threads are not competing for a single core, but for 2 cores, and the more cores the better, it will mean the capacity to process 80+ threads at a time is a plus in terms of performance.


    And if all threads need a common object? I mean it doesn't have a lot benefit then, if one thread is blocking that object for a certain amount of time...

    I'm wondering a lot how this is going to be automated. There is so much logic that can't be automatically applied. *curious about the future*

  • User profile image
    JohnAskew

    DigitalDud wrote:
    
    AndyC wrote: 
    Klaus Enevoldsen wrote: 

    This means that every time a program is doing something that could be done concurrently one should always start different threads (unless all threads depends on the same resources e.g. IO)



    Not quite. There is some overhead in spawning a thread so doing it for short lived tasks may be inefficient. Also, creating too many threads may degrade performance.



    If you need to thread a whole bunch of short-lived tasks you should consider using the thread pool.


    Great advice. Check Jeffrey Richter's MSDN article for some good advice using threadpool (every app already has one available).

  • User profile image
    Ang3lFir3

    the threadpool is your friend!!....

    A typical use where I personally use mutlithreading is in parsing flat files.... I have a directorywatcher watching a directory (in a windows service) that runs on its own thread.... each time it sees a new file it spawns a new thread to parse that file and upload it to a SQL db..... the parsing and uploading can take some time so threading allows me to parse multiple files at once (this cut the average parse time of 10+ files from a total of 30 seconds to an aprox 18sec total... IIRC)

    Remember its not just about Cores... its about logical processors.... HT-enabled procs/cores count as two processors....

  • User profile image
    Secret​Software

    I wanted to ask about Mulit-Core and Cryptographic systems.

    There are crypto systems that will not work now because the processor power is there. What new crypto systems are being developed for the Multi-Core world?

  • User profile image
    littleguru

    SecretSoftware wrote:
    I wanted to ask about Mulit-Core and Cryptographic systems.

    There are crypto systems that will not work now because the processor power is there. What new crypto systems are being developed for the Multi-Core world?


    Longer the key and you are safe with the existing ones. Cryptography has only a problem once quantum CPUs are available, but there are already people developing and have already developed ways to do quantum cryptography.

  • User profile image
    Secret​Software

    littleguru wrote:
    
    SecretSoftware wrote: I wanted to ask about Mulit-Core and Cryptographic systems.

    There are crypto systems that will not work now because the processor power is there. What new crypto systems are being developed for the Multi-Core world?


    Longer the key and you are safe with the existing ones. Cryptography has only a problem once quantum CPUs are available, but there are already people developing and have already developed ways to do quantum cryptography.


    But there are cryptographic hashes that will not be used anymore because of the Quad cores. Now its easier to guess the password from a hash. Or do Man-In-the middle attacks, because you have more processor power. remember the 80 core promise by 2010?

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.