为什么果黑骂苹果# Apple - 家有苹果
p*r
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;
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;