Skip to content

Instantly share code, notes, and snippets.

@edwintorok
Created August 25, 2020 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwintorok/139ed75a283e3e6bbab59ebfd033ccbe to your computer and use it in GitHub Desktop.
Save edwintorok/139ed75a283e3e6bbab59ebfd033ccbe to your computer and use it in GitHub Desktop.
diff -rwu chase-lev-deque/deque.c chase-lev-deque-bugfix/deque.c
--- chase-lev-deque/deque.c 2020-08-25 20:29:46.964661118 +0100
+++ chase-lev-deque-bugfix/deque.c 2020-08-25 20:29:46.963661116 +0100
@@ -50,7 +50,7 @@
for(i=top; i < bottom; i++) {
atomic_store_explicit(&new_a->buffer[i % new_size], atomic_load_explicit(&a->buffer[i % size], memory_order_relaxed), memory_order_relaxed);
}
- atomic_store_explicit(&q->array, new_a, memory_order_relaxed);
+ atomic_store_explicit(&q->array, new_a, memory_order_release);
printf("resize\n");
}
@@ -75,7 +75,7 @@
int x = EMPTY;
if (t < b) {
/* Non-empty queue. */
- Array *a = (Array *) atomic_load_explicit(&q->array, memory_order_relaxed);
+ Array *a = (Array *) atomic_load_explicit(&q->array, memory_order_acquire);
x = atomic_load_explicit(&a->buffer[t % atomic_load_explicit(&a->size, memory_order_relaxed)], memory_order_relaxed);
if (!atomic_compare_exchange_strong_explicit(&q->top, &t, t + 1, memory_order_seq_cst, memory_order_relaxed))
/* Failed race. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment