Skip to content

Instantly share code, notes, and snippets.

@winter-muted
Last active April 6, 2018 01:44
Show Gist options
  • Save winter-muted/4ad1cb3234fde5780bbb70212454106e to your computer and use it in GitHub Desktop.
Save winter-muted/4ad1cb3234fde5780bbb70212454106e to your computer and use it in GitHub Desktop.
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>*/
#include <iostream>
#include <future>
/* This function doesn't seem to have side effects,
* and is a great candidate for future static analysis
*/
float sum(double buf[],unsigned len)
{
auto res = 0;
int i;
for (i = 0; i <= len-1; i++)
res += buf[i];
return res;
}
int main(int argc, char** argv)
{
double a[8] = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0};
std::cout << "Enter a value: ";
unsigned len;
std::cin >> len;
auto handle = std::async(std::launch::async,sum,a,len);
std::cout << handle.get() << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment