Rizin
unix-like reverse engineering framework and cli tools
main.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <
uv.h
>
3
4
uv_barrier_t
blocker
;
5
uv_rwlock_t
numlock
;
6
int
shared_num
;
7
8
void
reader
(
void
*
n
)
9
{
10
int
num
= *(
int
*)
n
;
11
int
i
;
12
for
(
i
= 0;
i
< 20;
i
++) {
13
uv_rwlock_rdlock
(&
numlock
);
14
printf
(
"Reader %d: acquired lock\n"
,
num
);
15
printf
(
"Reader %d: shared num = %d\n"
,
num
,
shared_num
);
16
uv_rwlock_rdunlock
(&
numlock
);
17
printf
(
"Reader %d: released lock\n"
,
num
);
18
}
19
uv_barrier_wait
(&
blocker
);
20
}
21
22
void
writer
(
void
*
n
)
23
{
24
int
num
= *(
int
*)
n
;
25
int
i
;
26
for
(
i
= 0;
i
< 20;
i
++) {
27
uv_rwlock_wrlock
(&
numlock
);
28
printf
(
"Writer %d: acquired lock\n"
,
num
);
29
shared_num
++;
30
printf
(
"Writer %d: incremented shared num = %d\n"
,
num
,
shared_num
);
31
uv_rwlock_wrunlock
(&
numlock
);
32
printf
(
"Writer %d: released lock\n"
,
num
);
33
}
34
uv_barrier_wait
(&
blocker
);
35
}
36
37
int
main
()
38
{
39
uv_barrier_init
(&
blocker
, 4);
40
41
shared_num
= 0;
42
uv_rwlock_init
(&
numlock
);
43
44
uv_thread_t
threads
[3];
45
46
int
thread_nums[] = {1, 2, 1};
47
uv_thread_create
(&
threads
[0],
reader
, &thread_nums[0]);
48
uv_thread_create
(&
threads
[1],
reader
, &thread_nums[1]);
49
50
uv_thread_create
(&
threads
[2],
writer
, &thread_nums[2]);
51
52
uv_barrier_wait
(&
blocker
);
53
uv_barrier_destroy
(&
blocker
);
54
55
uv_rwlock_destroy
(&
numlock
);
56
return
0;
57
}
i
lzma_index ** i
Definition:
index.h:629
printf
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition:
cs_driver.c:93
main
int main(int argc, const char **argv)
Definition:
main.c:340
num
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition:
sflib.h:126
n
int n
Definition:
mipsasm.c:19
uv_barrier_t
Definition:
unix.h:156
reader
void reader(void *n)
Definition:
main.c:8
blocker
uv_barrier_t blocker
Definition:
main.c:4
shared_num
int shared_num
Definition:
main.c:6
writer
void writer(void *n)
Definition:
main.c:22
numlock
uv_rwlock_t numlock
Definition:
main.c:5
threads
static uv_thread_t * threads
Definition:
threadpool.c:38
uv_rwlock_t
Definition:
win.h:259
uv_thread_t
pthread_t uv_thread_t
Definition:
unix.h:136
uv.h
uv_barrier_init
UV_EXTERN int uv_barrier_init(uv_barrier_t *barrier, unsigned int count)
Definition:
thread.c:55
uv_rwlock_init
UV_EXTERN int uv_rwlock_init(uv_rwlock_t *rwlock)
Definition:
thread.c:356
uv_rwlock_wrlock
UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t *rwlock)
Definition:
thread.c:393
uv_rwlock_wrunlock
UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t *rwlock)
Definition:
thread.c:413
uv_barrier_wait
UV_EXTERN int uv_barrier_wait(uv_barrier_t *barrier)
Definition:
thread.c:89
uv_barrier_destroy
UV_EXTERN void uv_barrier_destroy(uv_barrier_t *barrier)
Definition:
thread.c:118
uv_rwlock_rdlock
UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t *rwlock)
Definition:
thread.c:367
uv_thread_create
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition:
thread.c:210
uv_rwlock_destroy
UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t *rwlock)
Definition:
thread.c:361
uv_rwlock_rdunlock
UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t *rwlock)
Definition:
thread.c:387
subprojects
libuv-v1.40.0
docs
code
locks
main.c
Generated by
1.9.1