Add the Linux Kernel style thread-based simple RCU.
It supports sparse checking [1].
With sparse, it will report:
main.c: note: in included file:
thrd_rcu.h:95:42: warning: Using plain integer as NULL pointer
thrd_rcu.h:95:42: warning: Using plain integer as NULL pointer
It is from the pthread_mutex_t initializer, we can ignore it.
[1] https://www.kernel.org/doc/html/latest/dev-tools/sparse.html
From the ThreadSanitizer report, ignore the volatile
type data race warning [1][2],
there still have the data race warning.
[reader 2835343104] 0
[reader 2826950400] 0
[reader 2818557696] 0
[reader 2810164992] 0
[reader 2801772288] 0
[updater 2793379584]
==================
WARNING: ThreadSanitizer: data race (pid=434539)
Write of size 8 at 0x7b0400000000 by thread T6:
#0 free ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:711 (libtsan.so.0+0x37ab8)
#1 updater_side /home/xxxx/linux2021/concurrent-programs/thrd_rcu/main.c:41 (main+0x1a38)
Previous read of size 4 at 0x7b0400000000 by thread T5:
#0 reader_side /home/xxxx/linux2021/concurrent-programs/thrd_rcu/main.c:23 (main+0x1898)
Thread T6 (tid=434546, running) created by main thread at:
#0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x605f8)
#1 main /home/xxxx/linux2021/concurrent-programs/thrd_rcu/main.c:59 (main+0x1429)
Thread T5 (tid=434545, finished) created by main thread at:
#0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x605f8)
#1 main /home/xxxx/linux2021/concurrent-programs/thrd_rcu/main.c:56 (main+0x13fd)
SUMMARY: ThreadSanitizer: data race /home/xxxx/linux2021/concurrent-programs/thrd_rcu/main.c:41 in updater_side
==================
[reader 2784986880] 2793379584
[reader 2744121088] 2793379584
[reader 2735728384] 2793379584
[reader 2727335680] 2793379584
[reader 2718942976] 2793379584
ThreadSanitizer: reported 1 warnings
I try to debug it, but cannot figure out where the wrong is.
Not sure if it is a false positive or not.
[1] https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547633.html
[2] https://gcc.gnu.org/gcc-11/changes.html