[Opensim-dev] .NET / Mono lock(obj) statement
Hurliman, John
john.hurliman at intel.com
Wed Jan 14 17:42:05 UTC 2009
I haven't heard of TryLock. Monitor.TryEnter would succeed if it was in the same thread (just as Monitor.Enter succeeds), in another thread it would wait until your timeout or until the last Monitor.Exit was called (right around where "Done" is printed).
John
> -----Original Message-----
> From: opensim-dev-bounces at lists.berlios.de [mailto:opensim-dev-
> bounces at lists.berlios.de] On Behalf Of Tedd Hansen
> Sent: Wednesday, January 14, 2009 9:36 AM
> To: opensim-dev at lists.berlios.de
> Subject: Re: [Opensim-dev] .NET / Mono lock(obj) statement
>
> Thanks for testing.
> What would TryLock return in the middle of this?
>
> My power supply died yesterday and took with it my C: so I can't test. :|
>
> -----Original Message----- From: opensim-dev-bounces at lists.berlios.de
> [mailto:opensim-dev-bounces at lists.berlios.de] On Behalf Of Hurliman,
> John Sent: 14. januar 2009 18:28 To: opensim-dev at lists.berlios.de
> Subject: Re: [Opensim-dev] .NET / Mono lock(obj) statement
>
> C# treats a monitor (lock statement) the same as Java. The same thread
> can reenter a lock as many times as it wishes. The following code
> completes as expected on .NET 3.5 SP1, Mono 1.9.1 (Windows), and Mono
> 1.9.1 (Ubuntu 8.10
> AMD64):
>
> using System;
>
> namespace sandbox
> {
> class Program
> {
> static void Main(string[] args)
> {
> object a = new object();
>
> Console.WriteLine("Starting");
>
> lock (a)
> {
> Console.WriteLine("Inside Main() lock");
>
> lock (a)
> {
> Console.WriteLine("Inside second Main() lock");
>
> F(a);
> }
> }
>
> Console.WriteLine("Done");
> }
>
> static void F(object a)
> {
> Console.WriteLine("Inside F()");
>
> lock (a)
> {
> Console.WriteLine("Inside F() lock");
> }
> }
> }
> }
>
>
>
>> -----Original Message-----
>> From: opensim-dev-bounces at lists.berlios.de [mailto:opensim-dev-
>> bounces at lists.berlios.de] On Behalf Of Diva Canto
>> Sent: Tuesday, January 13, 2009 8:58 PM
>> To: opensim-dev at lists.berlios.de
>> Subject: [Opensim-dev] .NET / Mono lock(obj) statement
>>
>> Hi everyone,
>>
>> Just got back from vacation to TP grief caused by extra locking
>> introduced in 7982. The extra locking is all good, but it seems that
>> certain things confuse the heck out of mono, so I thought I'd bring up
>> the issue here -- I'm pretty sure this problem occurs in other places
>> of the code too, so it's good to know what to expect. I'd certainly
>> like to find out more about the .NET spec.
>>
>> Here's a simplified version of the problem:
>>
>> lock (a)
>> {
>> foo();
>> }
>>
>> void foo()
>> {
>> lock (a)
>> {
>> ...
>> }
>> }
>>
>> (the real situation is a bit more complicated; foo() involves a
>> delegate; but ignore that)
>>
>> In Java, this situation does NOT result in locking, because it's the
>> same thread that's acquiring object a. I can't find the spec for
>> .NET for this particular issue, but I'd be very surprised if it is
>> different from Java. Nevertheless, mono was deadlocking here;
>> Windows was not. I find the mono behavior very strange.
>>
>> Crista
>>
>> _______________________________________________
>> Opensim-dev mailing list
>> Opensim-dev at lists.berlios.de
>> https://lists.berlios.de/mailman/listinfo/opensim-dev
> _______________________________________________ Opensim-dev mailing list
> Opensim-dev at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/opensim-dev
>
> _______________________________________________
> Opensim-dev mailing list
> Opensim-dev at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/opensim-dev
More information about the Opensim-dev
mailing list