| #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