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 
7 
8 void reader(void *n)
9 {
10  int num = *(int *)n;
11  int i;
12  for (i = 0; i < 20; i++) {
14  printf("Reader %d: acquired lock\n", num);
15  printf("Reader %d: shared num = %d\n", num, shared_num);
17  printf("Reader %d: released lock\n", num);
18  }
20 }
21 
22 void writer(void *n)
23 {
24  int num = *(int *)n;
25  int i;
26  for (i = 0; i < 20; i++) {
28  printf("Writer %d: acquired lock\n", num);
29  shared_num++;
30  printf("Writer %d: incremented shared num = %d\n", num, shared_num);
32  printf("Writer %d: released lock\n", num);
33  }
35 }
36 
37 int main()
38 {
40 
41  shared_num = 0;
43 
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 
54 
56  return 0;
57 }
lzma_index ** i
Definition: index.h:629
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
int main(int argc, const char **argv)
Definition: main.c:340
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
int n
Definition: mipsasm.c:19
void reader(void *n)
Definition: main.c:8
uv_barrier_t blocker
Definition: main.c:4
int shared_num
Definition: main.c:6
void writer(void *n)
Definition: main.c:22
uv_rwlock_t numlock
Definition: main.c:5
static uv_thread_t * threads
Definition: threadpool.c:38
pthread_t uv_thread_t
Definition: unix.h:136
UV_EXTERN int uv_barrier_init(uv_barrier_t *barrier, unsigned int count)
Definition: thread.c:55
UV_EXTERN int uv_rwlock_init(uv_rwlock_t *rwlock)
Definition: thread.c:356
UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t *rwlock)
Definition: thread.c:393
UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t *rwlock)
Definition: thread.c:413
UV_EXTERN int uv_barrier_wait(uv_barrier_t *barrier)
Definition: thread.c:89
UV_EXTERN void uv_barrier_destroy(uv_barrier_t *barrier)
Definition: thread.c:118
UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t *rwlock)
Definition: thread.c:367
UV_EXTERN int uv_thread_create(uv_thread_t *tid, uv_thread_cb entry, void *arg)
Definition: thread.c:210
UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t *rwlock)
Definition: thread.c:361
UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t *rwlock)
Definition: thread.c:387