Commit 70fd476a authored by Nelson Phillips's avatar Nelson Phillips
Browse files

autosave

parent 1291831e
#include <iostream>
#include <stdio.h>
#include "threadClass.h"
#include "ReadInput.h"
char ReadInput::collectInput (){
system("stty raw");
inputCh = getchar();
system("stty cooked");
return inputCh;
system("stty raw");
inputCh = getchar();
system("stty cooked");
return inputCh;
}
#ifndef THREADCLASS_H
#define THREADCLASS_H
#ifndef READINPUT_H
#define READINPUT_H
#include <iostream>
......
// thread example
#include <iostream> // std::cout
#include <thread> // std::thread
#include <unistd.h>
#include <stdio.h>
#include "threadFunc.cpp"
#include <iostream>
#include "ReadInput.h"
#include "Threads.h"
#include <thread>
using namespace std;
......@@ -17,23 +16,17 @@ int h = (rand() % 14);
int o = (rand() % 30);
char letter = ' ';
ReadInput inputRead;
char input;
void Sleep(float s) {
int sec = int(s*250000);
usleep(sec);
}
void charCall() {
for (int i = 0; i < 5000; i++){
input = inputRead.collectInput();
}
}
}
Thread Sneko;
void snakePrint(){
for (int i = 0; i < 5000; i++){
Sleep(1);
Sneko.Sleep(1);
system("stty cooked");
if(input == 'w'|| input == 'W')
x--;
......@@ -83,11 +76,19 @@ void charCall() {
}
}
int main()
{
thread first (charCall); // spawn new thread that calls input()
thread second (snakePrint); // spawn new thread that calls snakePrint(0)
cout << "main, input and snakePrint now execute concurrently...\n";
cout << "Press w,a,s,d to begin.";
// synchronize threads:
first.join(); // pauses until first finishes
......@@ -96,4 +97,5 @@ int main()
}
//g++ thread.cpp -o main.out -pthread -std=c++11 && ./main.out
\ No newline at end of file
//g++ *.cpp -o main.out -pthread -std=c++11 && ./main.out
//echo *.cpp
\ No newline at end of file
#include <iostream>
#include <thread>
#include <unistd.h>
#include "Threads.h"
void Thread::Sleep(float s){
int sec = int(s*250000);
usleep(sec);
}
\ No newline at end of file
#ifndef THREADS_H
#define THREADS_H
#include <iostream>
class Thread {
public:
void Sleep(float s);
};
#endif
\ 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