c# - Number of threads that can run in parallel on a single processor -
hello have started working threads in c# , have question not able clear answer. can multiple threads run in parallel on single core processor, or 1 thread can run @ time? i'm running following program on single core processor , see following output time: main called hello main done
which makes me wonder if ran on multi core processor see output as:
main called main done hello
static void main(string[] args) { console.writeline("main called"); thread thread = new thread(sayhello); thread.start(); console.writeline("main done"); console.readline(); } public static void sayhello() { console.writeline("hello"); }
a single-core processor can run 1 thread @ time, operating system uses mechanism switch between multiple running threads give appearance of concurrency. although threads aren't running in parallel, can never know when 1 thread stop , other start.
the many pitfalls of multi-threading still present, if have 1 core , 1 processor.
like blindy said, there various circumstances can affect thread runs @ time, can't rely on them.
Comments
Post a Comment