
Joel Salomon wrote:
Use mutexes. and In my experience, I hardly need just a container to be thead-safe. I usually need more data in addition to the container (which needs to be thread-safe). For instance, an extra latest_access_time, out_file, used_for_the_first_time, etc.
Thus, to me, the benefit of having a thread-safe container is very small. One thread-safe container that might be useful is a channel - a queue
John Torjo wrote: that one thread writes to and another reads to, the reader blocking when the channel is empty.
Right. This is the _only_ thread-safe(*) container (that I'm aware of) that is generally useful. Even here, there is a choice between non-blocking and blocking semantics (which preclude a lock-free implementation.) Having a max size implies blocking on push, of course. (*) For the implied definition of "thread safe" that we are using in this context ("strong" thread safety).