p*********r 发帖数: 48 | 1 No need to use any lock for a single producer single consumer queue. For
instance, I think the following code is multi-thread-safe. Am I right?
class myQueue
{
public:
struct Node {
Node (int v = 0) : value(v), next (0) {}
int value;
Node * next;
};
myQueue ()
{
first = last = new Node; // dummy node
}
~myQueue ()
{
while (first) {
Node * temp = first->next;
delete temp;
first = temp;
|
|