db0b68ca2d18cc58cc0bd163a938375773ec660c
4 * Userspace RCU library - test program
6 * Copyright February 2009 - Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
8 * Distributed under GPLv2
15 #include <sys/types.h>
28 static struct test_array
*test_rcu_pointer
;
34 void *thr_reader(void *arg
)
37 struct test_array
*local_ptr
;
39 printf("thread %s, thread id : %lu, pid %lu\n",
40 "reader", pthread_self(), (unsigned long)getpid());
43 urcu_register_thread();
45 for (i
= 0; i
< 100000; i
++) {
46 for (j
= 0; j
< 100000000; j
++) {
47 qparity
= rcu_read_lock();
48 local_ptr
= rcu_dereference(test_rcu_pointer
);
50 assert(local_ptr
->a
== 8);
51 assert(local_ptr
->b
== 12);
52 assert(local_ptr
->c
[55] == 2);
54 rcu_read_unlock(qparity
);
58 urcu_unregister_thread();
64 void *thr_writer(void *arg
)
67 struct test_array
*new, *old
;
69 printf("thread %s, thread id : %lu, pid %lu\n",
70 "writer", pthread_self(), (unsigned long)getpid());
73 for (i
= 0; i
< 10000000; i
++) {
74 new = malloc(sizeof(struct test_array
));
76 old
= test_rcu_pointer
;
80 assert(old
->c
[55] == 2);
85 old
= urcu_publish_content((void **)&test_rcu_pointer
, new);
87 /* can be done after unlock */
103 pthread_t tid_reader
[NR_READ
], tid_writer
[NR_WRITE
];
107 for (i
= 0; i
< NR_READ
; i
++) {
108 err
= pthread_create(&tid_reader
[i
], NULL
, thr_reader
, NULL
);
112 for (i
= 0; i
< NR_WRITE
; i
++) {
113 err
= pthread_create(&tid_writer
[i
], NULL
, thr_writer
, NULL
);
120 for (i
= 0; i
< NR_WRITE
; i
++) {
121 err
= pthread_join(tid_reader
[i
], &tret
);
125 for (i
= 0; i
< NR_WRITE
; i
++) {
126 err
= pthread_join(tid_writer
[i
], &tret
);
This page took 0.035467 seconds and 4 git commands to generate.