/* libcr_ipc/tests/test_mutex.c - Tests for * * Copyright (C) 2025 Luke T. Shumaker * SPDX-License-Identifier: AGPL-3.0-or-later */ #include #include #include "test.h" int counter = 0; COROUTINE cr_worker(void *_mu) { cr_mutex_t *mu = _mu; cr_begin(); for (int i = 0; i < 100; i++) { cr_mutex_lock(mu); int a = counter; cr_yield(); counter = a + 1; cr_mutex_unlock(mu); cr_yield(); } cr_end(); } int main() { cr_mutex_t mu = {0}; coroutine_add("a", cr_worker, &mu); coroutine_add("b", cr_worker, &mu); coroutine_main(); test_assert(counter == 200); return 0; }