Restore reader_count in case of failure in rwlock_rdlock_impl
What problem does this PR solve?
Issue Number: Fix #3051
Problem Summary:
What is changed and the side effects?
Changed:
Side effects:
-
Performance effects:
-
Breaking backward compatibility:
Check List:
- Please make sure your changes are compilable.
- When providing us with a new feature, it is best to add related tests.
- Please follow Contributor Covenant Code of Conduct.
LGTM
Please add a UT.
done
@chenBright please review,thank you
@chenBright
reader_semashould also be restored.- The same problem exists with
wlock.
In case of timeout, reader_sema will not be modified and does not require restoration. The same applies to rwlock->writer_sema. Perhaps I haven't uncovered the truth. Please point out the specific errors, thank you
bthread1 bthread2
bthread_sem_timedwait
rwlock->reader_count->fetch_add(RWLockMaxReaders);
bthread_sem_post_n
bthread_mutex_unlock
rwlock->reader_count->fetch_add
In this case, reader_sema has been posted. Subsequently, there may be a problem where the write lock and read lock enter the critical section at the same time.