From: Tony Johansson on
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


From: Random on
On May 12, 8:17 pm, "Tony Johansson" <johansson.anders...(a)telia.com>
wrote:
> 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.

From: Arne Vajhøj on
On 12-05-2010 20:17, Tony Johansson wrote:
> 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

From: Tony Johansson on

"Arne Vajh�j" <arne(a)vajhoej.dk> skrev i meddelandet
news:4beb54ad$0$279$14726298(a)news.sunsite.dk...
> On 12-05-2010 20:17, Tony Johansson wrote:
>> 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
>

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


From: Rick Lones on
Tony Johansson wrote:
> "Arne Vajh�j" <arne(a)vajhoej.dk> skrev i meddelandet
> news:4beb54ad$0$279$14726298(a)news.sunsite.dk...
>> On 12-05-2010 20:17, Tony Johansson wrote:
>>> 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
>>
>
> 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-