Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skyshaw committed May 12, 2012
2 parents 8159115 + 2442994 commit 7c6038e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
18 changes: 18 additions & 0 deletions c-cpp/misc/c++11/thread2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <iostream>
#include <thread>

void foo(int tid) {
std::cout << "Launched by thread " << tid << std::endl;
}
int main() {
const int num_threads = 10;
std::thread t[num_threads];
for (int i = 0; i < num_threads; ++i) {
t[i] = std::thread(foo, i);
}
std::cout << "Launched from the main" << std::endl;
for (int i = 0; i < num_threads; ++i) {
t[i].join();
}
return 0;
}
28 changes: 28 additions & 0 deletions c-cpp/misc/c++11/thread3.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <thread>
#include <string>

using namespace std;

class SaylHello{
public:
void func(const string &name) {
cout <<"Hello " << name << endl;
}
};

int main(int argc, char* argv[])
{
SaylHello x;

thread p(&SaylHello::func, &x, "Tom");

thread q([](string name) {
cout << "Hello " << name << endl;
}, "Jom");

p.join();
q.join();

return 0;
}
4 changes: 3 additions & 1 deletion c-cpp/misc/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ map:

.PHONY:
thread:
g++ $(CPP11)/thread1.cc -o $(BIN)/thread.o -std=c++0x -lpthread
g++ $(CPP11)/thread1.cc -o $(BIN)/thread1.o -std=c++0x -lpthread
g++ $(CPP11)/thread2.cc -o $(BIN)/thread2.o -std=c++0x -lpthread
g++ $(CPP11)/thread3.cc -o $(BIN)/thread3.o -std=c++0x -lpthread

.PHONY:
chrono:
Expand Down

0 comments on commit 7c6038e

Please sign in to comment.