PC Review


Reply
Thread Tools Rate Thread

Am I trapped over a pitfall (exposing static lock object)?

 
 
Lothar Behrens
Guest
Posts: n/a
 
      6th Jun 2011
Hi,

I have a class that uses a static lock object like this:

public class WSClientAgent
{
static object lockUpdateBunchOfData = "lock";

public object LockUpdateBunchOfData
{
get { return WSClientAgent.lockUpdateBunchOfData; }
set { WSClientAgent.lockUpdateBunchOfData = value; }
}

// ....
}

Internally I double checked that all thread relevant code uses a lock
statement. To ensure all stuff uses the correct locking, I have
exposed the static lock as an attribute.

But it seems that I still get errors that probably rooted to a missing
lock anywhere, or a pitfall with the above code.

Is there anything how I have solved my lock issues?

I am using a object relational mapper (database classes) that causing
any seldom problems. Some external code uses the exposed lock to also
synchronize the database access. That's why I have exposed it. Also I
haven't yet put all ORM related code inside the class that runs the
thread to avoid exposing.

It is merely impossible to do so as I would wrap an ORM :-)

It is a bit wired, as it is too seldom :-)


Thanks,

Lothar
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      7th Jun 2011
On 6/6/2011 6:32 AM, Lothar Behrens wrote:
> I have a class that uses a static lock object like this:
>
> public class WSClientAgent
> {
> static object lockUpdateBunchOfData = "lock";
>
> public object LockUpdateBunchOfData
> {
> get { return WSClientAgent.lockUpdateBunchOfData; }
> set { WSClientAgent.lockUpdateBunchOfData = value; }
> }
>
> // ....
> }
>
> Internally I double checked that all thread relevant code uses a lock
> statement. To ensure all stuff uses the correct locking, I have
> exposed the static lock as an attribute.
>
> But it seems that I still get errors that probably rooted to a missing
> lock anywhere, or a pitfall with the above code.
>
> Is there anything how I have solved my lock issues?


Depending on whether the resource you want to protect is really
single or not then either:
- drop set
- make field non static
or:
- drop set
- make field non static
- make class a singleton

> I am using a object relational mapper (database classes) that causing
> any seldom problems. Some external code uses the exposed lock to also
> synchronize the database access. That's why I have exposed it. Also I
> haven't yet put all ORM related code inside the class that runs the
> thread to avoid exposing.
>
> It is merely impossible to do so as I would wrap an ORM :-)


Usually an ORM should not require this type of synchronization. Just
setting the appropriate transaction isolation level should be
sufficient.

> It is a bit wired, as it is too seldom :-)


That is often the case with concurrency problems.

Arne
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Usercontrol exposing an object array from a contained control Johnny Jörgensen Microsoft C# .NET 3 13th Aug 2007 03:58 PM
GetIDispatchForObject / exposing an object to a scripting client mclp Microsoft VC .NET 2 2nd Mar 2007 05:48 AM
Static class method return non-static object? Paschalis Pagonidis Microsoft C# .NET 8 10th Nov 2004 10:10 AM
Exposing VB.NET object to COM in the old C format using Interop =?Utf-8?B?RG91Zw==?= Microsoft Dot NET Framework 3 17th Feb 2004 09:45 AM
Exposing VB.NET object to COM in the old C format using Interop =?Utf-8?B?RG91Zw==?= Microsoft Dot NET 1 13th Feb 2004 11:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:46 AM.