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

autosave

parent 1baffa59
......@@ -60,13 +60,6 @@ char letter = ' ';
}
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++){
cout << endl;
for (int q = 0; q < 14; q++){
......
......@@ -2,41 +2,39 @@
#include <iostream> // std::cout
#include <thread> // std::thread
#include <unistd.h>
#include <stdio.h>
using namespace std;
void Sleep(float s) {
char input;
void Sleep(float s) {
int sec = int(s*1000000);
usleep(sec);
}
void foo()
{
int e;
for (int i = 0; i < 5; i++){
Sleep(1);
cin >> e;
cout << " Foo " << e << endl;
}
void foo() {
for (int i = 0; i < 10; i++){
system("stty raw");
input = getchar();
system("stty cooked");
cout << endl;
}
}
void bar(int x){
for (int i = 0; i < 5; i++){
Sleep(2);
cout << " bar " << endl;
void bar(){
for (int i = 0; i < 10; i++){
Sleep(1);
cout << input << endl;
}
}
int main()
{
std::thread first (foo); // spawn new thread that calls foo()
std::thread second (bar,0); // spawn new thread that calls bar(0)
std::cout << "main, foo and bar now execute concurrently...\n";
thread first (foo); // spawn new thread that calls foo()
thread second (bar); // spawn new thread that calls bar(0)
cout << "main, foo and bar now execute concurrently...\n";
// synchronize threads:
first.join(); // pauses until first finishes
second.join(); // pauses until second finishes
std::cout << "foo and bar completed.\n";
return 0;
}
//g++ thread.cpp -o main.out -pthread -std=c++11 && ./main.out
\ No newline at end of file
Markdown is supported
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