From aacacbd331528a4cdf74683805ca4f4a482b98a6 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov <0x7fffff@guattari.ru> Date: Thu, 18 Aug 2022 18:49:24 +0400 Subject: [test] Fix cond var --- source/test/unittests/condition_variable.test.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/test/unittests/condition_variable.test.c b/source/test/unittests/condition_variable.test.c index 63b82b4..e16a336 100644 --- a/source/test/unittests/condition_variable.test.c +++ b/source/test/unittests/condition_variable.test.c @@ -16,18 +16,18 @@ static int test_run(void *p) { test_data_t *data = (test_data_t *) p; mtx_lock(&data->m); - data->value = 20; mtx_unlock(&data->m); + cnd_broadcast(&data->send); + mtx_lock(&data->m); cnd_wait(&data->receive, &data->m); - data->value = 22; - cnd_broadcast(&data->send); - mtx_unlock(&data->m); + cnd_broadcast(&data->send); + return 0; } @@ -40,18 +40,19 @@ TEST("condition variable") { thrd_t t; REQUIRE(thrd_create(&t, test_run, &data) == thrd_success); - + REQUIRE(mtx_lock(&data.m) == thrd_success); - REQUIRE(cnd_wait(&data.send, &data.m) == thrd_success); int x = data.value; + REQUIRE(mtx_unlock(&data.m) == thrd_success); REQUIRE(cnd_broadcast(&data.receive) == thrd_success); + REQUIRE(mtx_lock(&data.m) == thrd_success); REQUIRE(cnd_wait(&data.send, &data.m) == thrd_success); x += data.value; - REQUIRE(mtx_unlock(&data.m) == thrd_success); + REQUIRE(thrd_join(t, NULL) == thrd_success); mtx_destroy(&data.m); -- cgit v1.2.3