title: Memory order consume usage in C11
body: <p>I read about the <em>carries a dependency</em> relation and <em>dependency-ordered before</em> that uses one in its definition <code>5.1.2.4(p16)</code>:</p>
  
  <blockquote>
    <p>An evaluation <code>A</code> is dependency-ordered before an evaluation <code>B</code> if: </p>
    
    <p>— <code>A</code> performs a release operation on an atomic object <code>M</code>, and, in another
    thread, <code>B</code> performs a consume operation on <code>M</code> and reads a value written
    by any side effect in the release sequence headed by <code>A</code>, or </p>
    
    <p>— for some evaluation <code>X</code>, <code>A</code> is dependency-ordered before <code>X</code> and <code>X</code> carries a dependency to <code>B</code>.</p>
  </blockquote>
  
  <p>So I tried to craft an example where it might be useful. Here is it:</p>
  
  <pre><code>static _Atomic int i;
  
  void *produce(void *ptr){
      int int_value = *((int *) ptr);
      atomic_store_explicit(&amp;i, int_value, memory_order_release);
      return NULL;
  }
  
  void *consume(void *ignored){
      int int_value = atomic_load_explicit(&amp;i, memory_order_consume);
      int new_int_value = int_value + 42;
      printf("Consumed = %d\n", new_int_value);
  }
  
  int main(int args, const char *argv[]){
      int int_value = 123123;
      pthread_t t2;
      pthread_create(&amp;t2, NULL, &amp;produce, &amp;int_value);
  
      pthread_t t1;
      pthread_create(&amp;t1, NULL, &amp;consume, NULL);
  
      sleep(1000);
  }
  </code></pre>
  
  <p>In the function <code>void *consume(void*)</code> the <code>int_value</code> carries a dependency for <code>new_int_value</code> so if <code>atomic_load_explicit(&amp;i, memory_order_consume);</code> reads a value written by some <code>atomic_store_explicit(&amp;i, int_value, memory_order_release);</code> then <code>new_int_value</code> computation <em>dependency-ordered-before</em> the <code>atomic_store_explicit(&amp;i, int_value, memory_order_release);</code>. </p>
  
  <p>But what useful things can the dependency-ordered-before give us?</p>
  
  <p>I currently think that the <code>memory_order_consume</code> may well be replaced with <code>memory_order_acquire</code> without causing any data race...</p>