-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chapter 7. queue_mpmc.cpp #1
Comments
I encountered the same issue, and I assume you’ve resolved it. Let me supplement the solution to this problem: Memory Alignment Issue with counted_node_ptr Structure (May Occur in Certain Environments): struct counted_node_ptr {
int external_count;
node* ptr;
uint8_t padding[sizeof(void*) - sizeof(int)];
}; Then modify the push function: void push(T new_value) {
std::unique_ptr<T> new_data(new T(new_value));
counted_node_ptr new_next;
new_next.ptr = new node;
new_next.external_count = 1;
counted_node_ptr old_tail = tail.load();
for (;;) {
increase_external_count(tail, old_tail);
T* old_data = nullptr;
if (old_tail.ptr->data.compare_exchange_strong(old_data, new_data.get())) {
counted_node_ptr old_next = {0, nullptr, {0}};
if (!old_tail.ptr->next.compare_exchange_strong(old_next, new_next)) {
delete new_next.ptr;
new_next = old_next;
}
set_new_tail(old_tail, new_next);
new_data.release();
break;
} else {
counted_node_ptr old_next = {0, nullptr, {0}};
if (old_tail.ptr->next.compare_exchange_strong(old_next, new_next)) {
old_next = new_next;
new_next.ptr = new node;
}
set_new_tail(old_tail, old_next);
}
}
} Also, modify the node constructor: node() {
data = nullptr;
node_counter new_count;
new_count.internal_count = 0;
new_count.external_counters = 2;
count.store(new_count);
counted_node_ptr new_next {0, nullptr, {0}};
next.store(new_next);
} Improper Queue Initialization: lock_free_queue() {
counted_node_ptr dummy {1, new node, {0}};
head = dummy;
tail = dummy;
} That’s all. |
Hello subjum. I have tried to execution your realization of lock-free queue_mpmc, but i recevied segmenation fault (core dump) in push function. Can you help me with this problem, please?
The text was updated successfully, but these errors were encountered: