executing threads at the same time

T

Tony Johansson

Hi!

I will be sure that I have understood this correctly.
Assume you have a computer with two kernels and I run two additional threads
that run the same method
can then these two threads be executing fysically the exact same instruction
at the exact same time.

As fas as I understand this I mean you would still use the mechanism of
pre-emptive multitasking between these two threads.

I mean that you do have two threads executing at the same time but you still
use the mechanism of pre-emptive multitasking between them so at any singe
moment in time only one of these two threads is really executing an
instaruction while the other is waiting to get cpu time to continue
executing.

//Tony
 
R

Rick Lones

Tony said:
Hi!

I will be sure that I have understood this correctly.
Assume you have a computer with two kernels and I run two additional threads
that run the same method
can then these two threads be executing fysically the exact same instruction
at the exact same time.

Assuming you mean two CPU cores and not two kernels, then the answer is yes.
If you have two CPUs, then each is capable of independently running a given
instruction stream simultaneously with whatever the other one is doing. So in
principle they could be executing in lockstep different invocations of the same
instruction stream, although this would be highly unlikely. (If that's what you
really mean to ask here.)
As fas as I understand this I mean you would still use the mechanism of
pre-emptive multitasking between these two threads.

Yes, always.
I mean that you do have two threads executing at the same time but you still
use the mechanism of pre-emptive multitasking between them so at any singe
moment in time only one of these two threads is really executing an
instaruction while the other is waiting to get cpu time to continue
executing.

Well, yes. But now you are back to talking as if there is only one CPU core.
With one CPU you get multi-tasking. With multiple CPUs you get concurrent
execution where EACH core is being muli-tasked by the operating system.

HTH,
-rick-
 
A

Arne Vajhøj

I will be sure that I have understood this correctly.
Assume you have a computer with two kernels and I run two additional threads
that run the same method
can then these two threads be executing fysically the exact same instruction
at the exact same time.

As fas as I understand this I mean you would still use the mechanism of
pre-emptive multitasking between these two threads.

I mean that you do have two threads executing at the same time but you still
use the mechanism of pre-emptive multitasking between them so at any singe
moment in time only one of these two threads is really executing an
instaruction while the other is waiting to get cpu time to continue
executing.

If you have N execution units (approx. equals to cores for
modern desktop CPU's), then N thread can execute in parallel
on their own execution unit.

Preemptive multitasking does not mean just one thread executing. It
means that threads get removed from the CPU by the OS.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top