thread safe map 
Author Message
 thread safe map

Hi,
I wanted to know if there is any thread safe map container
in STL (or in any other c++ frameworks / libs).

Thanks,

Efrat



Sun, 03 Apr 2005 23:01:20 GMT  
 thread safe map
std::map shipped with all major STL implementations is likely to be
thread-safe in the usual sense, which is:

1. Two threads can concurrently access two different instances for
reading or writing
2. Multiple threads can concurrently access the same instance for
reading
3. While a thread modifies an instance, no other thread should access
the same instance for reading or writing. It is the responsibility of
the user to ensure this.

Containers that automatically protect themselves against concurrent
modifications do not (or at least should not) exist, because they don't
make sense: they are forced to lock at the wrong granularity. Consider
this:

int value = myMap[key];

Even in this simple statement, two operations are performed: first, a
key is searched for in the map, producing a reference to the element;
second, the referenced element is copied into the local variable. The
container can conceivably make the search atomic, but it has no way to
protect the copy operation - another thread can erase the element and
invalidate the reference before you have a chance to make a copy. Thus,
the user has to explicitly protect the complete operation anyway. The
overhead incurred when the container protected the search operation is
wasted.

Only the code at the application logic level knows the correct
granularity to lock at.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Hi,
> I wanted to know if there is any thread safe map container
> in STL (or in any other c++ frameworks / libs).

> Thanks,

> Efrat



Tue, 05 Apr 2005 00:07:30 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Thread safe Map

2. Thread safe Map

3. Thread Safe Map

4. Thread safe hash or map class?

5. Is STL map::find thread safe?

6. map.find thread safe ?

7. ANN: sigslot - C++ Portable, Thread-Safe, Type-Safe Signal/Slot Library

8. Using a non-thread-safe library with threads?

9. Thread functions are thread-safe?

10. how do i create thread safe worker thread

11. Is NetworkStream.Write() thread safe?

12. Why OleDbCommand objects are not thread safe?

 

 
Powered by phpBB® Forum Software