added comments

This commit is contained in:
portnoytmy 2025-06-03 01:40:44 +02:00
parent 70aad3fe1c
commit b12ae5b0cb
5 changed files with 120 additions and 27 deletions

View file

@ -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;