one processor with multiple core and threads

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi!

If you have a computer with one processor and multiple core and you lock a
section is it then possible
that two threads can lock this section simultaneously.
I mean when you have one processor with multiple core you can have two
threads executing simultaneously so
this would be possible.
What would happen you can't have two threads own the lock to a section of
code at the same time.

//Tony
 
If you have a computer with one processor and multiple core and you lock a
section is it then possible
that two threads can lock this section simultaneously.

No. Thats the point of a critical section.
 
If you have a computer with one processor and multiple core and you lock a
section is it then possible
that two threads can lock this section simultaneously.
I mean when you have one processor with multiple core you can have two
threads executing simultaneously so
this would be possible.
What would happen you can't have two threads own the lock to a section of
code at the same time.

With a lock on the same object then the two threads will not
execute the section code protected at the same time no matter
how many cores.

Arne
 
Arne Vajhøj said:
With a lock on the same object then the two threads will not
execute the section code protected at the same time no matter
how many cores.

Arne

I mean if you have this statement somewhere in the code
lock(locker)
{
.. . .
}

Then if I use one processor with multiple core is then possible that two
threads executes the statement lock(locker)
simultaneously so two threads has a lock on section of code ?

//Tony
 
Tony said:
I mean if you have this statement somewhere in the code
lock(locker)
{
. . .
}

Then if I use one processor with multiple core is then possible that two
threads executes the statement lock(locker)
simultaneously so two threads has a lock on section of code ?

//Tony

No, only one core will be granted the lock. There are hardware capabilities
which support software locking. The .Net runtime will be using those.

-rick-
 
I mean if you have this statement somewhere in the code
lock(locker)
{
. . .
}

Then if I use one processor with multiple core is then possible that two
threads executes the statement lock(locker)
simultaneously so two threads has a lock on section of code ?

lock(locker) may be reached by two threads, but the code inside
will not be executed in parallel, because one of the threads
will block in the lock statement until the other thread exits
the code section.

Arne
 
Back
Top