18 static struct test_array
*test_rcu_pointer
;
24 void *thr_reader(void *arg
)
27 struct test_array
*local_ptr
;
29 printf("thread %s, thread id : %lu, pid %lu\n",
30 "reader", pthread_self(), getpid());
33 urcu_register_thread();
35 for (i
= 0; i
< 1000; i
++) {
36 for (j
= 0; j
< 100000000; j
++) {
37 qparity
= rcu_read_lock();
38 local_ptr
= rcu_dereference(test_rcu_pointer
);
40 assert(local_ptr
->a
== 8);
41 assert(local_ptr
->b
== 12);
42 assert(local_ptr
->c
[55] == 2);
44 rcu_read_unlock(qparity
);
48 urcu_unregister_thread();
54 void *thr_writer(void *arg
)
57 struct test_array
*new, *old
;
59 printf("thread %s, thread id : %lu, pid %lu\n",
60 "writer", pthread_self(), getpid());
63 for (i
= 0; i
< 100000; i
++) {
65 new = malloc(sizeof(struct test_array
));
66 old
= test_rcu_pointer
;
70 assert(old
->c
[55] == 2);
75 old
= urcu_publish_content(&test_rcu_pointer
, new);
77 /* can be done after unlock */
93 pthread_t tid_reader
[NR_READ
], tid_writer
[NR_WRITE
];
97 for (i
= 0; i
< NR_READ
; i
++) {
98 err
= pthread_create(&tid_reader
[i
], NULL
, thr_reader
, NULL
);
102 for (i
= 0; i
< NR_WRITE
; i
++) {
103 err
= pthread_create(&tid_writer
[i
], NULL
, thr_writer
, NULL
);
110 for (i
= 0; i
< NR_WRITE
; i
++) {
111 err
= pthread_join(tid_reader
[i
], &tret
);
115 for (i
= 0; i
< NR_WRITE
; i
++) {
116 err
= pthread_join(tid_writer
[i
], &tret
);
This page took 0.03194 seconds and 5 git commands to generate.