Re: Share a read-only std::list between two threads



On 4 мар, 01:46, David Schwartz <dav...@xxxxxxxxxxxxx> wrote:
On Mar 3, 11:41 am, Marcin 'Qrczak' Kowalczyk <qrc...@xxxxxxxxxx>
wrote:

In theory yes, but a hash table which cares about threads emulates
safety guarantees of simple C types: concurrent reads should be safe.

So the questions is, do you have a hash table which cares about
threads?

I suspect that any serious C++ implementation which can be used with
multiple threads at all makes such guarantee, even if implicitly.

I would hope so. Threads and C++ are mature enough now that I think we
should be able to expect standard library types to work like normal
types. Hopefully, the number of exceptions to this rule will be small
and make sense.

I'm not so sure how far we've come on this front.

It's implementation-defined in C++.
MSDN explicitly states:

"The container classes are vector, deque, list, queue, stack,
priority_queue, valarray, map, hash_map, multimap, hash_multimap, set,
hash_set, multiset, hash_multiset, basic_string, and bitset.

A single object is thread safe for reading from multiple threads. For
example, given an object A, it is safe to read A from thread 1 and
from thread 2 simultaneously.

...

It is safe to read and write to one instance of a type even if another
thread is reading or writing to a different instance of the same type.
For example, given objects A and B of the same type, it is safe if A
is being written in thread 1 and B is being read in thread 2."

Dmitriy V'jukov
.



Relevant Pages

  • Re: Share a read-only std::list between two threads
    ... safety guarantees of simple C types: ... do you have a hash table which cares about ... multiple threads at all makes such guarantee, ...
    (comp.programming.threads)
  • Re: Static Functions in a Multi Threaded App
    ... arent accessing fields, doesn't mean that you won't run ... end up interweaving the writes to the file in between each other (if you did ... > Is it safe to create a static function in a multi threaded application ... > There are multiple threads in this application that call this function. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: threads and hashtable
    ... MSDN says that multiple threads doing reads is safe. ... is if my write thread is only adding new buckets to the ... the addmethod somehow modifies the general state of the hashtable ...
    (microsoft.public.dotnet.framework)
  • Re: 2 threading questions
    ... djc wrote: ... are all objects (value and reference type variables and objects/classes) ... safe to *read* from multiple threads? ... thread safe you have to use one of the synchronization features to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: 2 threading questions
    ... djc wrote: ... safe to *read* from multiple threads? ... thread safe you have to use one of the synchronization features to ...
    (microsoft.public.dotnet.languages.csharp)