Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dariosg committed Sep 30, 2020
1 parent bd0a8c8 commit a8fb0ca
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
20 changes: 19 additions & 1 deletion README.md
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
```
17 changes: 17 additions & 0 deletions code_examples/CMakeLists.txt
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)
12 changes: 12 additions & 0 deletions code_examples/hello_pacs.cc
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
}

21 changes: 21 additions & 0 deletions code_examples/hello_pacs_two_threads.cc
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));
}
}

23 changes: 23 additions & 0 deletions code_examples/thread_joinable.cc
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';
}

0 comments on commit a8fb0ca

Please sign in to comment.