[Dev-C++] making data structures thread safe
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Siva C. <siv...@ya...> - 2007-10-04 07:48:17
|
Hello all,
I am trying to understand on how to make a data
structure thread safe. I will use a simple example to
explain my problem.
Consider a class Array which encapsulates a 1d array
with the following definition:
<code>
class Array
{
public:
...
...
int& operator[](int index);
...
...
};
Array A(10); // a 10 element array
</code>
This array A can be accessed by two different threads
simultaneously - one thread could be reading a[5], and
another writing a[5]! How to protect my array from
such read/write conflicts? I am looking for a solution
which enables a user of the array class not to bother
about such conflicts. Is such a thing possible? If
yes, what is it?
Thanks and regards,
Siva Chandra
____________________________________________________________________________________
Check out the hottest 2008 models today at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html
|