What I am saying is that you cannot use it without any extra
synchronisation provided there are multiple producer and
consumer threads.
And?
The SGI implementation gives a contract concerning how you must
use them in a multi-threaded environment. You follow the
contract, and there should be no problems. You violate the
contract, and who knows. That's no different from anything
else.
In practice, of course, there's no sense in offering any other
contract, given the interface of the STL. Things like
operator[] and * on an iterator return references. So you can't
offer anything more than the basic contract that is present for
individual instances of the contained object. In the case of
the SGI implementation, this corresponds to the Posix contract.
And while I'm not saying that Posix is perfect, I would consider
its use of language "standard". And according to Posix, the SGI
contract is thread-safety.
That was my original warning what triggered your conditioned
reflex.
You didn't word it like that. If you had, I'd have agreed.
Let's be very clear: thread safety is a question of contract. A
component is thread safe *if* it specifies exactly what the
contract is in the presense of threads. We can argue the issue
a little, if the contract starts offering less guarantees that
the Posix, say (e.g. accessing two different objects requires
external synchronization), but there are limits. The STL
doesn't claim to provide synchronization; calling
deque<>::front() will *not* suspend your thread until there is
something in the queue. But this just seems so normal to me,
for a *container*, that I can't imagine anyone thinking
otherwise.
And for what its worth, the message queue I use between
processes is based on std::deque. And it's now being used in a
number of different applications, with no problems. Just as
obviously, there's some other code around it, to ensure
synchronization; this code does more than just protect accesses
to the queue, it suspends a thread if the queue is empty, etc.
(For the record, it uses both a pthread_cond_t and a
pthread_mutex_t.)
<quote>
Be aware that although STL is thread-safe to a certain extent, you
must wrap around the STL data structure to make a kind of a bounded
buffer out of it.
</quote>
http://groups.google.com/group/comp.lang.c++/msg/4450c4f92d6e0211
That is your homework to show a solution where two competing
threads are consuming from a "completely thread safe"
std::deque.
For various reasons, the actual code contains a lot of
"irrelevant" additions (templates, etc.), but it's really just
the classical implementation of a message queue under Posix,
with std::deque serving as the queuing mechanism.
Yes, you talk big like the Bandar-log, that you can do
that---but when it comes to show it, you escape with same
talk.
We are waiting for your report about your homework.
You're not my teacher. Since it's a classical implementation (I
think there's a similar example in the Butenhof), it seems like
a waste of time to post it here. The only really original thing
in it is the fact that I use std::auto_ptr in the interface, not
so much to manage memory as to ensure that once a thread has
passed an object off to the queue, it cannot access it any more.