-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathverify.c
64 lines (45 loc) · 1.25 KB
/
verify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2013-2024 The SRS Authors */
#include <stdio.h>
#include <st.h>
#include <assert.h>
st_mutex_t lock;
st_cond_t cond;
void* start(void* arg)
{
printf("ST: thread run\n");
printf("ST: thread wait for a while\n");
st_usleep(1.5 * 1000 * 1000);
printf("ST: thread wait done\n");
int r0 = st_cond_signal(cond);
printf("ST: thread cond signal, r0=%d\n", r0);
printf("ST: thread lock\n");
r0 = st_mutex_lock(lock);
assert(r0 == 0);
r0 = st_mutex_unlock(lock);
printf("ST: thread unlock\n");
return NULL;
}
int main(int argc, char** argv)
{
int r0 = st_init();
assert(r0 == 0);
printf("ST: main init ok\n");
lock = st_mutex_new();
cond = st_cond_new();
st_thread_t trd = st_thread_create(start, NULL, 1, 0);
printf("ST: main create ok\n");
printf("ST: main lock\n");
r0 = st_mutex_lock(lock);
assert(r0 == 0);
printf("ST: main cond waiting\n");
r0 = st_cond_wait(cond);
printf("ST: main cond wait ok, r0=%d\n", r0);
r0 = st_mutex_unlock(lock);
printf("ST: main unlock\n");
st_thread_join(trd, NULL);
printf("ST: main done\n");
st_mutex_destroy(lock);
st_cond_destroy(cond);
return 0;
}