Created
February 2, 2020 05:06
-
-
Save tbodt/d390c205d29f7d49e89597ec578f276a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#define ATOMIC 1 | |
int flags; | |
void *thread(void *asdf) { | |
(void) asdf; | |
for (;;) { | |
#if ATOMIC | |
__atomic_fetch_or(&flags, 1 << 3, __ATOMIC_SEQ_CST); | |
__atomic_fetch_and(&flags, ~(1 << 3), __ATOMIC_SEQ_CST); | |
#else | |
flags |= 1 << 3; | |
flags &= ~(1 << 3); | |
#endif | |
} | |
return NULL; | |
} | |
int main() { | |
pthread_t t; | |
pthread_create(&t, NULL, thread, NULL); | |
pthread_detach(t); | |
for (;;) { | |
#if ATOMIC | |
__atomic_fetch_or(&flags, 1 << 5, __ATOMIC_SEQ_CST); | |
__atomic_fetch_and(&flags, ~(1 << 5), __ATOMIC_SEQ_CST); | |
#else | |
flags |= 1 << 5; | |
flags &= ~(1 << 5); | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment