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
| // Peterson's algorithm in C++11 atomics | |
| // | |
| // Adapted from Dmitry Vyukov's example in the comments to https://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering/. | |
| // For a correctness argument, see https://www.justsoftwaresolutions.co.uk/threading/petersons_lock_with_C++0x_atomics.html. | |
| #include <atomic> | |
| #include <immintrin.h> | |
| constexpr size_t CACHE_LINE_SIZE = 64; | |
| struct alignas(CACHE_LINE_SIZE) |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher64EntriesTwoChoices: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a word-size bitvector | |
| self.size_exp: int = size_exp |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher64EntriesOneChoice: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a word-size bitvector | |
| self.size_exp: int = size_exp |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher32EntriesTwoChoices: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a word-size bitvector | |
| self.size_exp: int = size_exp |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher32EntriesOneChoice: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a word-size bitvector | |
| self.size_exp: int = size_exp |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher16EntriesTwoChoices: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a word-size bitvector | |
| self.size_exp: int = size_exp |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher16EntriesOneChoice: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a word-size bitvector | |
| self.size_exp: int = size_exp |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher8EntriesTwoChoices: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a byte-size bitvector | |
| self.size_exp: int = size_exp |
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
| #!/usr/bin/env python3 | |
| import numpy | |
| class BinHasher8EntriesOneChoice: | |
| def __init__(self, size_exp: int) -> None: | |
| # each bin is represented by a byte-size bitvector | |
| self.size_exp: int = size_exp |
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
| #include "atomik.hpp" | |
| void increment_balance(const char* account_name, int32 amount) | |
| { | |
| atomik::do_atomically( | |
| []() { | |
| atomik::var<Account> account_var = atomik::get_var_by_key(account_name); | |
| auto account = account_var.get(); | |
| account.balance += amount; | |
| account_var.set(account); |
NewerOlder