added comments
This commit is contained in:
parent
70aad3fe1c
commit
b12ae5b0cb
5 changed files with 120 additions and 27 deletions
|
|
@ -1,16 +1,30 @@
|
|||
#pragma once
|
||||
#include <mutex>
|
||||
|
||||
/**
|
||||
* Thread-sicheres Analysemodell
|
||||
* Vereinfachte Implementierung mit:
|
||||
* - Einfachem Mutex-Schutz (kein Reader-Writer-Lock)
|
||||
* - Für seltene Schreibzugriffe geeignet
|
||||
*/
|
||||
class AnalysisModel {
|
||||
int value = 0;
|
||||
std::mutex mtx;
|
||||
int value = 0; // Der gespeicherte Wert
|
||||
std::mutex mtx; // Schützt Lese/Schreibzugriffe
|
||||
|
||||
public:
|
||||
/**
|
||||
* Liest den aktuellen Wert
|
||||
* @return Der gespeicherte Wert
|
||||
*/
|
||||
int read() {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schreibt einen neuen Wert
|
||||
* @param new_val Der neue Wert
|
||||
*/
|
||||
void write(int new_val) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
value = new_val;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue