Bug #1189 ยป reproduce_bug.patch
userspace-rcu-0.10.2/doc/examples/rculfhash/cds_lfht_destroy.c 2019-07-12 15:11:38.270598030 +0800 | ||
---|---|---|
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <time.h>
|
||
#include <unistd.h>
|
||
#include <urcu.h> /* RCU flavor */
|
||
#include <urcu/rculfhash.h> /* RCU Lock-free hash table */
|
||
#include <urcu/compiler.h> /* For CAA_ARRAY_SIZE */
|
||
... | ... | |
int main(int argc, char **argv)
|
||
{
|
||
int values[] = { -5, 42, 42, 36, 24, }; /* 42 is duplicated */
|
||
int values[512]; /* 42 is duplicated */
|
||
struct cds_lfht *ht; /* Hash table */
|
||
unsigned int i;
|
||
unsigned int i,j;
|
||
int ret = 0;
|
||
uint32_t seed;
|
||
struct cds_lfht_iter iter; /* For iteration on hash table */
|
||
... | ... | |
* Each thread need using RCU read-side need to be explicitly
|
||
* registered.
|
||
*/
|
||
for (i = 0; i< 512;i++) {
|
||
values[i] = i;
|
||
}
|
||
rcu_register_thread();
|
||
for (j =0;j < 200000; j++) {
|
||
/* Use time as seed for hash table hashing. */
|
||
seed = (uint32_t) time(NULL);
|
||
... | ... | |
rcu_read_lock();
|
||
cds_lfht_add(ht, hash, &node->node);
|
||
rcu_read_unlock();
|
||
//usleep(500);
|
||
}
|
||
/*
|
||
... | ... | |
* random order, depending on the hash seed. Iteration needs to
|
||
* be performed within RCU read-side critical section.
|
||
*/
|
||
printf("hash table content (random order):");
|
||
//printf("hash table content (random order):");
|
||
rcu_read_lock();
|
||
cds_lfht_for_each_entry(ht, &iter, node, node) {
|
||
printf(" %d", node->value);
|
||
//printf(" %d", node->value);
|
||
}
|
||
rcu_read_unlock();
|
||
printf("\n");
|
||
//printf("\n");
|
||
/*
|
||
* Make sure all hash table nodes are removed before destroying.
|
||
*/
|
||
printf("removing all nodes:");
|
||
//printf("removing all nodes:");
|
||
rcu_read_lock();
|
||
cds_lfht_for_each_entry(ht, &iter, node, node) {
|
||
ht_node = cds_lfht_iter_get_node(&iter);
|
||
ret = cds_lfht_del(ht, ht_node);
|
||
printf(" %d", node->value);
|
||
//printf(" %d", node->value);
|
||
if (ret) {
|
||
printf(" (concurrently deleted)");
|
||
} else {
|
||
call_rcu(&node->rcu_head, free_node);
|
||
}
|
||
//usleep(500);
|
||
}
|
||
rcu_read_unlock();
|
||
printf("\n");
|
||
//printf("current time: %d\n",j);
|
||
/*
|
||
* cds_lfht_destroy() must be called from a very specific
|
||
* context: it needs to be called from a registered RCU reader
|
||
... | ... | |
if (ret) {
|
||
printf("Destroying hash table failed\n");
|
||
}
|
||
if (j%5000 == 0) {
|
||
printf("repeat %d times\n",j);
|
||
}
|
||
}
|
||
end:
|
||
if (j != 99999) {
|
||
printf("only repeat %d times\n",j);
|
||
}
|
||
rcu_unregister_thread();
|
||
return ret;
|
||
}
|
userspace-rcu-0.10.2/doc/examples/rculfhash/Makefile.cds_lfht_destroy 2019-07-04 10:33:38.860003818 +0800 | ||
---|---|---|
DEPS = jhash.h
|
||
OBJECTS = $(EXAMPLE_NAME).o
|
||
BINARY = $(EXAMPLE_NAME)
|
||
LIBS = -lurcu-cds -lurcu
|
||
#LIBS = -lurcu-cds -lurcu
|
||
LIBS = -L /usr/lib64/
|
||
LIBS += -lurcu-cds -lurcu-signal
|
||
CFLAGS += -D RCU_SIGNAL
|
||
include ../Makefile.examples.template
|