1515
1616using namespace pmem ::obj;
1717
18- /* In this example we will be using concurrent_hash_map with p<int> type for
19- * both keys and values */
18+ /* In this example we use concurrent_hash_map with p<int> type as
19+ * both keys and values. */
2020using hashmap_type = concurrent_hash_map<p<int >, p<int >>;
2121
2222const int THREADS_NUM = 30 ;
2323
2424/* This is basic example and we only need to use concurrent_hash_map. Hence we
25- * will correlate memory pool root object with single instance of persistent
26- * pointer to hasmap_type */
25+ * correlate memory pool root object with a single instance of persistent
26+ * pointer to hashmap_type. */
2727struct root {
2828 persistent_ptr<hashmap_type> pptr;
2929};
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
7373
7474 r->runtime_initialize ();
7575
76- /* defragment the whole pool at the beginning */
76+ /* Defragment the whole pool at the beginning. */
7777 try {
7878 r->defragment ();
7979 } catch (const pmem::defrag_error &e) {
@@ -89,8 +89,8 @@ main(int argc, char *argv[])
8989 std::vector<std::thread> threads;
9090 threads.reserve (static_cast <size_t >(THREADS_NUM));
9191
92- /* Insert THREADS_NUM / 3 key-value pairs to the hashmap. This
93- * operation is thread-safe. */
92+ /* Start THREADS_NUM/3 threads to insert key-value pairs
93+ * to the hashmap. This operation is thread-safe. */
9494 for (int i = 0 ; i < THREADS_NUM / 3 ; ++i) {
9595 threads.emplace_back ([&]() {
9696 for (int i = 0 ; i < 10 * THREADS_NUM; ++i) {
@@ -100,8 +100,8 @@ main(int argc, char *argv[])
100100 });
101101 }
102102
103- /* Erase THREADS_NUM /3 key-value pairs from the hashmap. This
104- * operation is thread-safe. */
103+ /* Start THREADS_NUM/3 threads to erase key-value pairs
104+ * from the hashmap. This operation is thread-safe. */
105105 for (int i = 0 ; i < THREADS_NUM / 3 ; ++i) {
106106 threads.emplace_back ([&]() {
107107 for (int i = 0 ; i < 10 * THREADS_NUM; ++i) {
@@ -110,8 +110,9 @@ main(int argc, char *argv[])
110110 });
111111 }
112112
113- /* Check if given key is in the hashmap. For the time of an
114- * accessor life, the read-write lock is taken on the item. */
113+ /* Start THREADS_NUM/3 threads to check if given key is
114+ * in the hashmap. For the time of an accessor life,
115+ * the read-write lock is taken on the item. */
115116 for (int i = 0 ; i < THREADS_NUM / 3 ; ++i) {
116117 threads.emplace_back ([&]() {
117118 for (int i = 0 ; i < 10 * THREADS_NUM; ++i) {
@@ -132,7 +133,7 @@ main(int argc, char *argv[])
132133 t.join ();
133134 }
134135 try {
135- /* defragment the whole pool at the end */
136+ /* Defragment the whole pool at the end. */
136137 map.defragment ();
137138 } catch (const pmem::defrag_error &e) {
138139 std::cerr << " Defragmentation exception: " << e.what ()
@@ -176,8 +177,7 @@ main(int argc, char *argv[])
176177 map.free_data ();
177178
178179 /* map.clear() // WRONG
179- * After free_data() concurrent hash map cannot be used
180- * anymore! */
180+ * After free_data() hash map cannot be used anymore! */
181181
182182 transaction::run (pop, [&] {
183183 delete_persistent<hashmap_type>(r);
0 commit comments