Commit 5d9fc366 authored by Nelson Phillips's avatar Nelson Phillips
Browse files

autosave

parent 1baffa59
...@@ -60,13 +60,6 @@ char letter = ' '; ...@@ -60,13 +60,6 @@ char letter = ' ';
} }
cout << "Your score is : " << score << endl; cout << "Your score is : " << score << endl;
// ANSI Escape sequence for clearing the screen
// \e[1;1H moves the cursor to row 1 column 1
// \e[2J clears the screen
// Look at http://www.isthe.com/chongo/tech/comp/ansi_escapes.html for how to set these up
//cout << "\e[1;1H\e[2J";
for (int i = 0; i < 14; i++){ for (int i = 0; i < 14; i++){
cout << endl; cout << endl;
for (int q = 0; q < 14; q++){ for (int q = 0; q < 14; q++){
......
...@@ -2,41 +2,39 @@ ...@@ -2,41 +2,39 @@
#include <iostream> // std::cout #include <iostream> // std::cout
#include <thread> // std::thread #include <thread> // std::thread
#include <unistd.h> #include <unistd.h>
#include <stdio.h>
using namespace std; using namespace std;
void Sleep(float s) { char input;
void Sleep(float s) {
int sec = int(s*1000000); int sec = int(s*1000000);
usleep(sec); usleep(sec);
} }
void foo() void foo() {
{ for (int i = 0; i < 10; i++){
int e; system("stty raw");
for (int i = 0; i < 5; i++){ input = getchar();
Sleep(1); system("stty cooked");
cin >> e; cout << endl;
cout << " Foo " << e << endl; }
}
} }
void bar(){
void bar(int x){ for (int i = 0; i < 10; i++){
for (int i = 0; i < 5; i++){ Sleep(1);
Sleep(2); cout << input << endl;
cout << " bar " << endl;
} }
} }
int main() int main()
{ {
std::thread first (foo); // spawn new thread that calls foo() thread first (foo); // spawn new thread that calls foo()
std::thread second (bar,0); // spawn new thread that calls bar(0) thread second (bar); // spawn new thread that calls bar(0)
cout << "main, foo and bar now execute concurrently...\n";
std::cout << "main, foo and bar now execute concurrently...\n";
// synchronize threads: // synchronize threads:
first.join(); // pauses until first finishes first.join(); // pauses until first finishes
second.join(); // pauses until second finishes second.join(); // pauses until second finishes
std::cout << "foo and bar completed.\n";
return 0; return 0;
} }
//g++ thread.cpp -o main.out -pthread -std=c++11 && ./main.out
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment