added sources and a quote to notes
This commit is contained in:
+6
-5
@@ -1,25 +1,26 @@
|
||||
// from: http://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
static const int num_threads = 10;
|
||||
|
||||
//This function will be called from a thread
|
||||
static const int num_threads = 8;
|
||||
|
||||
void call_from_thread(int tid) {
|
||||
std::cout << "Launched by thread " << tid << std::endl;
|
||||
double x = 1.0;
|
||||
for(int i = 0; i < 2E9; i++) {
|
||||
x /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::thread t[num_threads];
|
||||
|
||||
//Launch a group of threads
|
||||
for (int i = 0; i < num_threads; ++i) {
|
||||
t[i] = std::thread(call_from_thread, i);
|
||||
}
|
||||
|
||||
std::cout << "Launched from the main\n";
|
||||
|
||||
//Join the threads with the main thread
|
||||
for (int i = 0; i < num_threads; ++i) {
|
||||
t[i].join();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user