Could someone recommend good book on how to write thread safe containers?
thanks
Thread safe containers are no silver bullet!
E.g. this code is not thread safe, whatever container you use:
if (!container.has(value)) container.add(value);
Neither is:
container[value] = container[value] + 42;
Code can be made thread safe, but it requires a lot more than thread safe containers.
It's even worse: thread safe containers won't buy you much. They may help for simple cases you'll find in text books, but in the more complicated cases that exist in practice, you will need a lock anyway (see above for typical cases). Using a thread safe container in that case will be purely overhead.
Have a look at Java, as it started with thread safe containers. After a couple of years Java switched to thread unsafe containers and deprecated the old, thread safe, containers.
So my advice: do not look for thread safe containers. Instead, look for a good book how to write thread safe code.
UPDATE for clarification: I'm talking about the standard containers, like vector, map, and string.
1024cores.net is chock full of good articles about writing thread safe code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With