|
1 | | -# WaitFreeHashMap |
| 1 | +# WaitFreeCollections |
| 2 | + |
| 3 | +<table> |
| 4 | + <tr> |
| 5 | + <td><strong>master branch</strong></td> |
| 6 | + <td> |
| 7 | + <a href="https://ci.appveyor.com/project/CBenoit/waitfreecollections/branch/master"><img src="https://ci.appveyor.com/api/projects/status/sucn29if5de65t01/branch/master?svg=true"></a> |
| 8 | + </td> |
| 9 | + </tr> |
| 10 | + <tr> |
| 11 | + <td><strong>develop branch</strong></td> |
| 12 | + <td> |
| 13 | + <a href="https://ci.appveyor.com/project/CBenoit/waitfreecollections/branch/develop"><img src="https://ci.appveyor.com/api/projects/status/sucn29if5de65t01/branch/develop?svg=true"></a> |
| 14 | + </td> |
| 15 | + </tr> |
| 16 | + <tr> |
| 17 | + <td><strong>License</strong></td> |
| 18 | + <td> |
| 19 | + <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg"></a> |
| 20 | + </td> |
| 21 | + </tr> |
| 22 | +</table> |
| 23 | + |
| 24 | +A header-only library providing wait-free collections such as hash map and double ended queue (deque). |
| 25 | + |
| 26 | +## Wait-Free Hash Map |
| 27 | + |
| 28 | +An implementation of a wait-free hash map as described in the article |
2 | 29 |
|
3 | | -An implementation of an hashmap described in the article: |
4 | 30 | > P. Laborde, S. Feldman et D. Dechev, « A Wait-Free Hash Map », <br> |
5 | 31 | > International Journal of Parallel Programming, t. 45, n o 3, p. 421-448, 2017, issn : 1573-7640. <br> |
6 | 32 | > doi : https://doi.org/10.1007/s10766-015-0376-3 |
7 | 33 |
|
8 | | -# Copyright |
| 34 | +See [unordered_map example](./examples/unordered_map_example.cpp) in `examples` folder. |
9 | 35 |
|
10 | | -License: MIT |
| 36 | +## Double ended queue (Deque) |
| 37 | + |
| 38 | +WIP |
11 | 39 |
|
12 | | -# Requirements |
| 40 | +## Requirements |
13 | 41 |
|
14 | 42 | - Compiler which supports C++17 |
15 | 43 | - CMake ≥ 3.10 |
| 44 | + |
| 45 | +## Minimal unordered map example |
| 46 | + |
| 47 | +```cpp |
| 48 | +#include <iostream> |
| 49 | +#include <thread> |
| 50 | + |
| 51 | +#include <wfc/unordered_map.hpp> |
| 52 | + |
| 53 | +constexpr int nbr_threads = 16; |
| 54 | + |
| 55 | +int main() |
| 56 | +{ |
| 57 | + wfc::unordered_map<std::size_t, std::size_t> m(4, nbr_threads, nbr_threads); |
| 58 | + |
| 59 | + std::array<std::thread, nbr_threads> threads; |
| 60 | + for (std::size_t i = 0; i < nbr_threads; ++i) |
| 61 | + { |
| 62 | + threads[i] = std::thread([&m, i]() { |
| 63 | + m.insert(i, i); |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + for (auto& t: threads) |
| 68 | + { |
| 69 | + t.join(); |
| 70 | + } |
| 71 | + |
| 72 | + m.visit([](std::pair<const std::size_t, std::size_t> p) { |
| 73 | + std::cout << '[' << p.first << '-' << p.second << "]\n"; |
| 74 | + }); |
| 75 | + |
| 76 | + return 0; |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +This should output: |
| 81 | + |
| 82 | +``` |
| 83 | +[0-0] |
| 84 | +[1-1] |
| 85 | +[2-2] |
| 86 | +[3-3] |
| 87 | +[4-4] |
| 88 | +[5-5] |
| 89 | +[6-6] |
| 90 | +[7-7] |
| 91 | +[8-8] |
| 92 | +[9-9] |
| 93 | +[10-10] |
| 94 | +[11-11] |
| 95 | +[12-12] |
| 96 | +[13-13] |
| 97 | +[14-14] |
| 98 | +[15-15] |
| 99 | +``` |
| 100 | + |
| 101 | +## How to import the library using CMake |
| 102 | + |
| 103 | +To include the library, you may copy / paste the content of this repository in a subfolder (such as `externals`) or use a git submodule. |
| 104 | + |
| 105 | +Then, in you CMakeLists.txt file, you just have to do something similar to: |
| 106 | + |
| 107 | +```cmake |
| 108 | +cmake_minimum_required(VERSION 3.10) |
| 109 | +project(MyProject) |
| 110 | +enable_language(CXX) |
| 111 | +set(CMAKE_CXX_STANDARD 17) |
| 112 | +
|
| 113 | +add_subdirectory(externals/WaitFreeCollections) |
| 114 | +
|
| 115 | +find_package(Threads REQUIRED) # you'll probably need that one too |
| 116 | +
|
| 117 | +add_executable(MyTarget src/main.cpp) |
| 118 | +target_link_libraries(MyTarget Threads::Threads WaitFreeCollections) |
| 119 | +``` |
| 120 | + |
| 121 | +At this point, the project hierarchy looks like: |
| 122 | + |
| 123 | +``` |
| 124 | +|- CMakeLists.txt |
| 125 | +|- src/ |
| 126 | + |- main.cpp |
| 127 | +|- externals/ |
| 128 | + |- WaitFreeCollections/ |
| 129 | + |- ... |
| 130 | +``` |
| 131 | + |
| 132 | +You may try to use the minimal example above as your `main.cpp`. |
| 133 | + |
| 134 | +Also, since this is a header-only library, you may copy / paste the content of the include folder in your |
| 135 | +project to achieve similar results (maybe a little bit less clean though). |
| 136 | + |
| 137 | +## Build targets |
| 138 | + |
| 139 | +You don't need to actually build the library beforehand to use it in your project due to the "header-only" nature of it. |
| 140 | +The build targets in this repository are for tests, exemples and code formatting. |
| 141 | +These are good to know should you contribute to this project or play with the exemples. |
| 142 | + |
| 143 | +First, you need to create a sub-directory to run `cmake` from it. Then you can build using `make`. |
| 144 | + |
| 145 | +``` |
| 146 | +$ mkdir build |
| 147 | +$ cmake .. -DWFC_BUILD_ALL=1 |
| 148 | +``` |
| 149 | + |
| 150 | +By default, everything is build in Release mode. You can pass `-DCMAKE_BUILD_TYPE=Debug` to `cmake` to ask Debug builds. |
| 151 | +This will also activate useful features for developing purposes such as the holy warnings. |
| 152 | +The `-DWFC_BUILD_ALL=1` parameter will tell CMake to include all our targets in the build process. |
| 153 | + |
| 154 | +CMake will generate several targets that you can build separately using the `--target` parameter: |
| 155 | + |
| 156 | +- `UnorderedMapExample1` |
| 157 | +- `UtilityTests` |
| 158 | +- `UnorderedMapTests` |
| 159 | +- `Clang-format` |
| 160 | + |
| 161 | +For instance, to build the `UnorderedMapTests` run |
| 162 | + |
| 163 | +``` |
| 164 | +$ cmake --build . --target UnorderedMapTests |
| 165 | +``` |
| 166 | + |
| 167 | +You can also build everything by not giving any specific target. |
| 168 | +Produced executables are inside the `bin` folder. |
| 169 | + |
| 170 | +Note that the `Clang-format` target does not produce anything. |
| 171 | +It just run the clang formatter. |
| 172 | +Also this target needs to be called explicitly. |
| 173 | + |
| 174 | +For more details, see the [CMakeLists.txt](CMakeLists.txt) file. |
| 175 | + |
| 176 | +## Copyright |
| 177 | + |
| 178 | +License: MIT |
| 179 | + |
| 180 | +Main contributors: |
| 181 | + |
| 182 | +- [Jérôme Boulmier](https://github.com/Lomadriel) |
| 183 | +- [Benoît Cortier](https://github.com/CBenoit) |
0 commit comments