summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitya Selivanov <0x7fffff@guattari.ru>2022-08-18 18:49:24 +0400
committerMitya Selivanov <0x7fffff@guattari.ru>2022-08-18 18:49:24 +0400
commitaacacbd331528a4cdf74683805ca4f4a482b98a6 (patch)
tree011f2c24af0b4a9dbd3aab929c003c40ed086cc7
parentcdef2868a8d3b61ca1a4027aa925f6df0047dd93 (diff)
downloadkit-aacacbd331528a4cdf74683805ca4f4a482b98a6.zip
[test] Fix cond var
-rw-r--r--source/test/unittests/condition_variable.test.c15
1 files 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);