@@ -15,7 +15,7 @@ constexpr auto total = 1u << tree_height;
1515void update_max (std::atomic<int >& max_val, int const & value)
1616{
1717 int old = max_val;
18- while (old < value and not max_val.compare_exchange_weak (old, value));
18+ while (old < value && ! max_val.compare_exchange_weak (old, value));
1919}
2020
2121int maxCrossingSum (std::vector<int >& vec, int l, int m, int r){
@@ -49,7 +49,7 @@ void maxSubArraySum(std::vector<int>& vec, int l, int r, std::atomic<int>& max_n
4949 // Base Case: Only one element
5050 if (l == r) {
5151 update_max (max_num, vec[l]);
52- if (++counter == total){
52+ if (++counter == total* 2 - 1 ){
5353 promise.set_value ();
5454 }
5555 return ;
@@ -62,7 +62,7 @@ void maxSubArraySum(std::vector<int>& vec, int l, int r, std::atomic<int>& max_n
6262 tp.silent_async ([&, m=m, r=r](){ maxSubArraySum (vec, m+1 , r, max_num, tp, counter, promise); });
6363
6464 update_max (max_num, maxCrossingSum (vec, l, m, r));
65- if (++counter == total){
65+ if (++counter == total* 2 - 1 ){
6666 promise.set_value ();
6767 }
6868}
@@ -82,7 +82,7 @@ auto subsum(std::vector<int>& vec){
8282 }
8383 auto end = std::chrono::high_resolution_clock::now ();
8484 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
85- // std::cout << result << '\n';
85+ // std::cout << counter << '\n';
8686 return elapsed.count ();
8787}
8888
0 commit comments