#include <threads.h>
#include <stdbool.h>
static int a;
static int b;
mtx_t flag_mutex;
bool init_all(int type) {
a = 0;
b = 0;
if (thrd_success != mtx_init(&flag_mutex, type)) {
return false;
}
return true;
}
int get_sum(void) {
if (thrd_success != mtx_lock(&flag_mutex)) {
}
int sum = a + b;
if (thrd_success != mtx_unlock(&flag_mutex)) {
}
return sum;
}
void set_values(int new_a, int new_b) {
if (thrd_success != mtx_lock(&flag_mutex)) {
}
a = new_a;
b = new_b;
if (thrd_success != mtx_unlock(&flag_mutex)) {
}
}