Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
1
142GameCenter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nelson Phillips
142GameCenter
Commits
70fd476a
Commit
70fd476a
authored
Mar 01, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
1291831e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
19 deletions
+52
-19
Testings/Nelson's YEET/ReadInput.cpp
Testings/Nelson's YEET/ReadInput.cpp
+11
-0
Testings/Nelson's YEET/ReadInput.h
Testings/Nelson's YEET/ReadInput.h
+2
-2
Testings/Nelson's YEET/Snake.cpp
Testings/Nelson's YEET/Snake.cpp
+19
-17
Testings/Nelson's YEET/Threads.cpp
Testings/Nelson's YEET/Threads.cpp
+9
-0
Testings/Nelson's YEET/Threads.h
Testings/Nelson's YEET/Threads.h
+11
-0
No files found.
Testings/Nelson's YEET/
threadFunc
.cpp
→
Testings/Nelson's YEET/
ReadInput
.cpp
View file @
70fd476a
#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
;
}
Testings/Nelson's YEET/
threadClass
.h
→
Testings/Nelson's YEET/
ReadInput
.h
View file @
70fd476a
#ifndef
THREADCLASS
_H
#define
THREADCLASS
_H
#ifndef
READINPUT
_H
#define
READINPUT
_H
#include <iostream>
...
...
Testings/Nelson's YEET/
thread
.cpp
→
Testings/Nelson's YEET/
Snake
.cpp
View file @
70fd476a
// 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
);
S
neko
.
S
leep
(
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
Testings/Nelson's YEET/Threads.cpp
0 → 100644
View file @
70fd476a
#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
Testings/Nelson's YEET/Threads.h
0 → 100644
View file @
70fd476a
#ifndef THREADS_H
#define THREADS_H
#include <iostream>
class
Thread
{
public:
void
Sleep
(
float
s
);
};
#endif
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment