This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,27 @@
#include <thread>
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
int main()
{
std::random_device rd;
std::mt19937 eng(rd()); // mt19937 generator with a hardware random seed.
std::uniform_int_distribution<> dist(1,1000);
std::vector<std::thread> threads;
for(auto& str: {"Enjoy\n", "Rosetta\n", "Code\n"}) {
// between 1 and 1000ms per our distribution
std::chrono::milliseconds duration(dist(eng));
threads.push_back(std::thread([str, duration](){
std::this_thread::sleep_for(duration);
std::cout << str;
}));
}
for(auto& t: threads) t.join();
return 0;
}

View file

@ -0,0 +1,20 @@
#include <iostream>
#include <ppl.h> // MSVC++
void a(void) { std::cout << "Eat\n"; }
void b(void) { std::cout << "At\n"; }
void c(void) { std::cout << "Joe's\n"; }
int main()
{
// function pointers
Concurrency::parallel_invoke(&a, &b, &c);
// C++11 lambda functions
Concurrency::parallel_invoke(
[]{ std::cout << "Enjoy\n"; },
[]{ std::cout << "Rosetta\n"; },
[]{ std::cout << "Code\n"; }
);
return 0;
}

View file

@ -1,4 +1,3 @@
#lang racket
(for ([str '("Enjoy" "Rosetta" "Code")])
(thread (λ () (displayln str))))