contributed by <yaohwang99
>
A successful call to pthread_create() stores the ID of the new thread in the buffer pointed to by readers + i
, return 0
and starts execution by invoking reader_thread
Both EXP3 and EXP4 is list_remove(&dom->retired, ptr)
because the function cleanup
iterates through the list and deallocate if ptr
is in the retired
list and not in pointers
list.
With the following configuration and ThreadSanitizer, several error will occur.
That is because we didn't mark the data as hazard when writing.
shared_confing
may be written before or after line 10 and cause data race.
Improve:
Just like in read_thread()
, use load
to mark the data as hazard and drop when we no longer need the data.
Note that in line 22, the flag is set as DEFER_DEALLOC
because deadlock will occur if cleanup_ptr
spins until data is unused.
Hazard Pointer:
RCU synchronizer:
rcu_read_lock()
and rcu_read_unlock
.synchronize_rcu()
when other reader is in critical section.I believe that Linux uses RCU because hazard pointer is implemented by different data structure for different types of data. Whereas RCU is implemented the same way, so it is easier to write the code to fit every scenario.