473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Thread safe

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

Dec 14 '05 #1
3 1120

Access it as a web service.

Newbee wrote:
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

Dec 14 '05 #2
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

"John Bailo" <ja*****@texeme.com> wrote in message
news:43**************@texeme.com...

Access it as a web service.

Newbee wrote:
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

Dec 14 '05 #3
Vadym Stetsyak wrote:
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 ); } }
}

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.
Leon Lambert
Dec 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
11
by: dee | last post by:
OleDbCommand class like many .NET classes has the following description in its help file: "Thread Safety Any public static (Shared in Visual Basic) members of this type are safe for...
3
by: tcomer | last post by:
Hello! I'm working on an asynchronous network application that uses multiple threads to do it's work. I have a ChatClient class that handles the basic functionality of connecting to a server and...
15
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
1
by: jecheney | last post by:
Hi, Im currently using the following code for reading/writing to a network socket. private StreamReader clientStreamReader; private StreamWriter clientStreamWriter; .... TcpClient tcpClient...
13
by: arun.darra | last post by:
Are the following thread safe: 1. Assuming Object is any simple object Object* fn() { Object *p = new Object(); return p; } 2. is return by value thread safe?
12
by: Peter K | last post by:
Say I have this class public class Simple { private string name; public string Name { get { return name; } set { name = value; }
44
by: climber.cui | last post by:
Hi all, Does anyone have experience on the thread-safty issue with malloc()? Some people said this function provided in stdlib.h is not thread- safe, but someone said it is thread safe. Is it...
13
by: Henri.Chinasque | last post by:
Hi all, I am wondering about thread safety and member variables. If I have such a class: class foo { private float m_floater = 0.0; public void bar(){ m_floater = true; }
29
by: NvrBst | last post by:
I've read a bit online seeing that two writes are not safe, which I understand, but would 1 thread push()'ing and 1 thread pop()'ing be thread-safe? Basically my situation is the follows: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.