Commit a7fd44a7 authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent 24f3ff35
#include <iostream>
#include <vector>
using namespace std;
#include <stdio.h>
#include <unistd.h>
using namespace std;
void Sleep(float s)
{
int sec = int(s*1000000);
usleep(sec);
}
main(){
char grid[15][15];
int x = 0;
......@@ -38,6 +44,8 @@ char letter = ' ';
else
if(input == 'd'|| input == 'D')
y++;
else
x++;
system("stty cooked");
......@@ -51,6 +59,8 @@ char letter = ' ';
cout << 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
......@@ -84,3 +94,6 @@ char letter = ' ';
}
}
// thread example
#include <iostream> // std::cout
#include <thread> // std::thread
#include <unistd.h>
using namespace std;
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 bar(int x){
for (int i = 0; i < 5; i++){
Sleep(2);
cout << " bar " << 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";
// synchronize threads:
first.join(); // pauses until first finishes
second.join(); // pauses until second finishes
std::cout << "foo and bar completed.\n";
return 0;
}
// https://stackoverflow.com/questions/17274032/c-threads-stdsystem-error-operation-not-permitted
\ 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