Skip to content

Instantly share code, notes, and snippets.

@atomictom
Created April 22, 2015 04:23
Show Gist options
  • Save atomictom/95fb14b773656d31c3e8 to your computer and use it in GitHub Desktop.
Save atomictom/95fb14b773656d31c3e8 to your computer and use it in GitHub Desktop.
{% highlight c linenos %}
void bitset(unsigned char * array, int index){
int newval;
int oldval;
int bitset_index = index / BITS_PER_INDEX;
int bit_index = index % BITS_PER_INDEX;
do{
oldval = array[bitset_index];
newval = oldval | (1 << (bit_index));
}while(!__sync_bool_compare_and_swap(&array[bitset_index], oldval, newval));
}
{% endhighlight %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment