Skip to content

Commit 07fb388

Browse files
author
Adam Horvath
committed
fix makefile
tweak Async
1 parent f47734c commit 07fb388

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

.cproject

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
1717
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1324808345" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
1818
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1324808345." name="/" resourcePath="">
19-
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.2058173028" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
19+
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.2058173028" name="Linux GCC" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.exe.debug" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
2020
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.631645193" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
21-
<builder buildPath="${workspace_loc:/cpp11}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.59758397" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
21+
<builder arguments="-std=c++11 -o cpp11 *.cpp" buildPath="${workspace_loc:/cpp11/src}" command="clang++" id="cdt.managedbuild.target.gnu.builder.exe.debug.428551382" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
2222
<tool id="cdt.managedbuild.tool.gnu.archiver.base.719411554" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
2323
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1313804263" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
2424
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1699704852" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>

src/Async.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,29 @@ Async::~Async() {}
1515

1616
void Async::GetForecasts() const
1717
{
18-
auto debrecen = std::async( GetCityForecast, std::string("Debrecen") );
19-
auto lima = std::async( GetCityForecast, "Lima" );
20-
auto norberg = std::async( GetCityForecast, "Norberg" );
21-
auto piemonte = std::async( GetCityForecast, "Piemonte" );
18+
auto debrecen = std::async( std::launch::async, GetCityForecast, std::string("Debrecen") );
19+
auto lima = std::async( std::launch::async, GetCityForecast, "Lima" );
20+
auto norberg = std::async( std::launch::async, GetCityForecast, "Norberg" );
21+
auto piemonte = std::async( std::launch::async, GetCityForecast, "Piemonte" );
2222

2323
// Perform other tasks here while temperatures get fetched
24+
std::this_thread::sleep_for(std::chrono::seconds(8));
2425

2526
std::cout << "Temperature Forecasts: " << std::endl;
2627
std::cout << "Debrecen: " << debrecen.get() << std::endl;
27-
std::cout << "Lima: " << lima.get() << std::endl;
28-
std::cout << "Norberg: " << norberg.get() << std::endl;
28+
std::cout << "Lima: " << lima.get() << std::endl;
29+
std::cout << "Norberg: " << norberg.get() << std::endl;
2930
std::cout << "Piemonte: " << piemonte.get() << std::endl;
3031
}
3132

3233

3334

3435
int Async::GetCityForecast( const std::string& city )
3536
{
36-
auto seed = reinterpret_cast<const __int64_t>(&city);
37-
std::srand(seed);
38-
3937
// Fake calulation time
40-
int delay = 2 + std::rand() % 8;
38+
int delay = 2 + std::rand() % 6;
4139
std::this_thread::sleep_for(std::chrono::seconds(delay));
42-
40+
std::cout << "Calculated: " << city << std::endl;
4341
int temperature = -5 + std::rand() % 40;
4442
return temperature;
4543
}

src/make

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
clang++ -std=c++14 -o cpp11 *.cpp
1+
clang++ -std=c++14 -o cpp11 -pthread *.cpp

0 commit comments

Comments
 (0)