Rizin
unix-like reverse engineering framework and cli tools
main.c File Reference
#include <stdio.h>
#include <uv.h>

Go to the source code of this file.

Functions

void reader (void *n)
 
void writer (void *n)
 
int main ()
 

Variables

uv_barrier_t blocker
 
uv_rwlock_t numlock
 
int shared_num
 

Function Documentation

◆ main()

int main ( void  )

Definition at line 37 of file main.c.

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 }
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 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 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

References blocker, numlock, reader(), shared_num, threads, uv_barrier_destroy(), uv_barrier_init(), uv_barrier_wait(), uv_rwlock_destroy(), uv_rwlock_init(), uv_thread_create(), and writer().

◆ reader()

void reader ( void *  n)

Definition at line 8 of file main.c.

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 }
lzma_index ** i
Definition: index.h:629
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
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
UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t *rwlock)
Definition: thread.c:367
UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t *rwlock)
Definition: thread.c:387

References blocker, i, n, num, numlock, printf(), shared_num, uv_barrier_wait(), uv_rwlock_rdlock(), and uv_rwlock_rdunlock().

Referenced by main().

◆ writer()

void writer ( void *  n)

Definition at line 22 of file main.c.

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 }
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

References blocker, i, n, num, numlock, printf(), shared_num, uv_barrier_wait(), uv_rwlock_wrlock(), and uv_rwlock_wrunlock().

Referenced by main(), and ts_subtree__write_to_string().

Variable Documentation

◆ blocker

uv_barrier_t blocker

Definition at line 4 of file main.c.

Referenced by main(), reader(), and writer().

◆ numlock

uv_rwlock_t numlock

Definition at line 5 of file main.c.

Referenced by main(), reader(), and writer().

◆ shared_num

int shared_num

Definition at line 6 of file main.c.

Referenced by main(), reader(), and writer().