Skip to content

Instantly share code, notes, and snippets.

@milesrout
Last active August 29, 2015 14:18
Show Gist options
  • Save milesrout/e2f62cfaa13e7c077622 to your computer and use it in GitHub Desktop.
Save milesrout/e2f62cfaa13e7c077622 to your computer and use it in GitHub Desktop.
mutexes
#include <stdatomic.h>
int main()
{
static atomic_flag mutex = ATOMIC_FLAG_INIT;
static unsigned volatile counter = 0;
while (atomic_flag_test_and_set(&mutex));
++counter;
atomic_flag_clear(&mutex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment