Compare commits
3 commits
master
...
complicate
| Author | SHA1 | Date | |
|---|---|---|---|
| 1612d8988d | |||
| e71c96d825 | |||
| 9e3a746ebf |
7 changed files with 9 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -22,6 +22,7 @@ Makefile
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
./sensor_network
|
||||||
|
|
||||||
# IDE-spezifische Dateien
|
# IDE-spezifische Dateien
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
### Erklärung der Praktikumsaufgabe (Synchronisation)
|
/* ### Erklärung der Praktikumsaufgabe (Synchronisation)
|
||||||
|
|
||||||
#### **Kernziel der Aufgabe**
|
#### **Kernziel der Aufgabe**
|
||||||
Sie sollen ein **multithreaded Sensornetzwerk** simulieren, das drei Komponenten umfasst:
|
Sie sollen ein **multithreaded Sensornetzwerk** simulieren, das drei Komponenten umfasst:
|
||||||
|
|
@ -151,4 +151,5 @@ Starten Sie das System mit verschiedenen Parametern und beobachten Sie:
|
||||||
Mit dieser Struktur erfüllen Sie alle Lernziele:
|
Mit dieser Struktur erfüllen Sie alle Lernziele:
|
||||||
✅ Reader-Writer-Problem
|
✅ Reader-Writer-Problem
|
||||||
✅ Producer-Consumer-Pattern
|
✅ Producer-Consumer-Pattern
|
||||||
✅ Vermeidung von Race Conditions & Deadlocks!
|
✅ Vermeidung von Race Conditions & Deadlocks!
|
||||||
|
*/
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
class AnalysisModel {
|
class AnalysisModel {
|
||||||
int value = 0;
|
int value = 0;
|
||||||
int reader_count = 0;
|
int reader_count = 0;
|
||||||
|
|
||||||
std::mutex model_mutex;
|
std::mutex model_mutex;
|
||||||
std::mutex count_mutex;
|
std::mutex count_mutex;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ private:
|
||||||
std::vector<int> data;
|
std::vector<int> data;
|
||||||
size_t read_ptr = 0;
|
size_t read_ptr = 0;
|
||||||
size_t write_ptr = 0;
|
size_t write_ptr = 0;
|
||||||
bool full = false;
|
bool full = false;
|
||||||
|
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
std::condition_variable not_empty;
|
std::condition_variable not_empty;
|
||||||
|
|
|
||||||
BIN
sensor_network
BIN
sensor_network
Binary file not shown.
|
|
@ -44,7 +44,7 @@ void SensorNetwork<N>::sensor_thread(int id) {
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::mt19937 gen(rd());
|
std::mt19937 gen(rd());
|
||||||
std::uniform_int_distribution<> data_gen(0, 100);
|
std::uniform_int_distribution<> data_gen(0, 100);
|
||||||
std::uniform_int_distribution<> sleep_gen(100, 500);
|
std::uniform_int_distribution<> sleep_gen(100, 500);
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
std::this_thread::sleep_for(
|
std::this_thread::sleep_for(
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
class SensorNetwork {
|
class SensorNetwork {
|
||||||
RingBuffer<N> buffer;
|
RingBuffer<N> buffer;
|
||||||
AnalysisModel model;
|
AnalysisModel model;
|
||||||
std::atomic<bool> running{false};
|
std::atomic<bool> running{false};
|
||||||
|
|
||||||
std::vector<std::thread> sensors;
|
std::vector<std::thread> sensors;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue