25 lines
307 B
C
25 lines
307 B
C
|
//
|
||
|
// Created by Christopher Hamer on 19/06/2024.
|
||
|
//
|
||
|
|
||
|
#include <mutex>
|
||
|
|
||
|
#ifndef TASK1_SUM_H
|
||
|
#define TASK1_SUM_H
|
||
|
|
||
|
|
||
|
// Thread-safe sum accumulator
|
||
|
class SumAccumulator {
|
||
|
public:
|
||
|
void add(int value);
|
||
|
|
||
|
long long getTotal();
|
||
|
|
||
|
private:
|
||
|
long long sum = 0;
|
||
|
std::mutex mtx;
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif //TASK1_SUM_H
|