From: Arne Vajhøj on
On 13-05-2010 05:11, 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.
>
> 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