forked from saul205/PACS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
# PACS | ||
Official repository of the Programming and Architecture of Computing Systems course of the MS in Robotics, Graphics, and Computer Vision | ||
|
||
Official repository of the Programming and Architecture of Computing Systems | ||
course of the MS in Robotics, Graphics, and Computer Vision | ||
|
||
## Code snippets from Class | ||
|
||
The directory `code_examples` contains many of the small C++ programs and | ||
fragments from the slides. | ||
|
||
To compile them, you can use `cmake`. For example: | ||
|
||
```bash | ||
cd code_examples | ||
mkdir build | ||
cd build | ||
cmake ../ # generate the Makefile with cmake | ||
make # compile the examples | ||
ls # list the examples | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required (VERSION 3.1) | ||
project (PACS_EXAMPLES) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
if (MSVC) | ||
# warning level 4 and all warnings as errors | ||
add_compile_options(/W4 /WX) | ||
else() | ||
# lots of warnings and all warnings as errors | ||
add_compile_options(-Wall -Wextra -pedantic -Werror) | ||
endif() | ||
|
||
add_executable(hello_pacs hello_pacs.cc) | ||
add_executable(thread_joinable thread_joinable.cc) | ||
add_executable(hello_pacs_two_threads hello_pacs_two_threads.cc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <iostream> | ||
#include <thread> | ||
|
||
void hello() { | ||
std::cout << "Hello PACS" << std::endl; | ||
} | ||
|
||
int main() { | ||
std::thread t(hello); | ||
t.join(); // wait for completion | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <chrono> | ||
#include <iostream> | ||
#include <thread> | ||
|
||
using namespace std::chrono; | ||
|
||
void hello() { | ||
while(1) { | ||
std::cout << "Hello" << std::endl; | ||
std::this_thread::sleep_for(milliseconds(300)); | ||
} | ||
} | ||
|
||
int main() { | ||
std::thread t(hello); // thread creation | ||
while(1) { | ||
std::cout << "PACS" << std::endl; | ||
std::this_thread::sleep_for(milliseconds(300)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <iostream> | ||
#include <thread> | ||
#include <chrono> | ||
|
||
void foo() | ||
{ | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
} | ||
|
||
int main() | ||
{ | ||
std::thread t; | ||
std::cout << "before starting, joinable: " << std::boolalpha << t.joinable() | ||
<< '\n'; | ||
|
||
t = std::thread(foo); | ||
std::cout << "after starting, joinable: " << t.joinable() | ||
<< '\n'; | ||
|
||
t.join(); | ||
std::cout << "after joining, joinable: " << t.joinable() | ||
<< '\n'; | ||
} |