Wednesday, 15 February 2012

c# - Number of threads that can run in parallel on a single processor -


Hello, I have recently started working with thread in C # and there is a question that I get clear answers Was not able to. Can multiple threads run in parallel on a single core processor, or can only run one thread at a time? I am running the following program on a single core processor and I see the following output all the time: main name hello main

which makes me wonder if I run it on a multi-core processor View the output as:

The main name by the main name

  Fixed zero main (string [] args) {Console.WriteLine ("main called"); Thread thread = new thread (chenha); Thread.Start (); Console.light line ("main done"); Console.ReadLine (); } Public stable zero (hello) (console) WriteLine ("hello"); }  

The single-core processor can only run one thread at a time, but the operating The system uses a mechanism to switch between multiple running threads to give the presence of interaction. Although the threads are not actually running in parallel, you never know when a thread will stop and the second start.

Many losses of multi-threading still exist, even if you have only one core and one processor.

As told by Blindy, there are many situations that can affect the thread that runs at that time, but you can not really trust them.


No comments:

Post a Comment