Created
October 4, 2022 11:34
-
-
Save maudzekod4000/96713bc948beb89c3316c4fa79fa0025 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
| #include <iostream> | |
| #include <vector> | |
| #include <math.h> | |
| #include <unordered_map> | |
| #include <string> | |
| #include <fstream> | |
| #include <stack> | |
| #include <unordered_set> | |
| #include <queue> | |
| #include <stack> | |
| #include <limits> | |
| #include <thread> | |
| #include <set> | |
| #include <array> | |
| #include <future> | |
| using namespace std; | |
| int sum(vector<int>::iterator begin, vector<int>::iterator end, int count) { | |
| int sum = 0; | |
| while (begin != end) { | |
| sum += *begin; | |
| begin++; | |
| } | |
| return sum; | |
| } | |
| int main() { | |
| vector<int> numbers = { 1,2,3,4,5,6 }; | |
| std::promise<int> sumPromise; | |
| std::future<int> sumFuture = sumPromise.get_future(); | |
| auto job = std::thread([&] { | |
| int val = sum(numbers.begin(), numbers.end(), numbers.size()); | |
| sumPromise.set_value(val); | |
| }); | |
| int sumata = sumFuture.get(); | |
| job.join(); | |
| cout << sumata << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment