Created
November 6, 2016 14:09
-
-
Save fcamel/48c8f2f8f3835319645df18fefbc52e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Source: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1525.htm | |
const int num_mailboxes = 32; | |
_Atomic volatile int mailbox[num_mailboxes]; | |
void MailboxInspection(int my_id, void (*do_work)(int)) { | |
for (int i = 0; i < num_mailboxes; i++) { | |
if (atomic_load_explicit(&mailbox[i], memory_order_relaxed) == my_id) { | |
atomic_thread_fence(memory_order_acquire); // prevent speculative reads in do_work [7.17.4.1] | |
do_work(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment