all groups > dotnet general > december 2005 >
You're in the

dotnet general

group:

Thread safe


Thread safe Newbee
12/13/2005 9:02:29 PM
dotnet general:
Looking for some suggetions on the following..

I have an array that gets filled by multiple application. Same instance
of this array(static array) will be accessed by multiple applications.

ie there will be applications that fill this array and som application
applications that retrieves elements one by one and process and delete
entries from the array. How do I ensure thread safety for this array?

Thanks in advance
Re: Thread safe John Bailo
12/13/2005 9:34:12 PM

Access it as a web service.

[quoted text, click to view]
Re: Thread safe Leon Lambert
12/14/2005 7:35:42 AM
[quoted text, click to view]
This really would not be a lot of help. You lock the object then get the
length and then return. Now he has a length that might change in the
next fraction of a second by another thread so any logic he does on it
would be in error.

You should design an object to manage your data. The applications should
never get direct access to the array. This smart object should then have
methods to support the business logic that the applications need. The
methods would do their work within a lock block to ensure thread safety.
The applications should know nothing about locking the data structures.
Just the new manager object should. Another good practice is to use
queues for requesting work of the manager object in case it needs to do
some background calculations. This is a good way to avoid deadlock
situations.

Hope this help.
Re: Thread safe Vadym Stetsyak
12/14/2005 11:21:06 AM
IMO WebService will be inefficient in this scenario.

you can use simple lock statement in the server, and wrap the access to
array.

e.g.

public int Count
{
get { lock(this) { return ( _array.Length ); } }
}

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

[quoted text, click to view]

AddThis Social Bookmark Button