Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

您好,我想请教一下代码有关代码线程安全相关的内容 #13

Open
I-Rinka opened this issue Feb 11, 2023 · 2 comments
Open

Comments

@I-Rinka
Copy link

I-Rinka commented Feb 11, 2023

在class SkipList 中的 insert_elementdelete_element中,开头的一行使用 mtx.lock(); 尝试给数据结构上了锁,不过作为查找的 search_element 却没有上锁。这么做有个问题,虽然它避免了写-写数据竞争,但是没有避免读-写数据竞争,我并不确定在多线程环境下这样依然是安全的,例如某一线程在free的的时候另一线程仍然在读以及使用指针。

@LearningStarChen
Copy link

hxd,会不会是这样的呢,我读的时候并不在意正在写的数据呢,也就是即时的。比如一个线程在写kv,但是他没有写进去,那么我读的时候默认就是不读这个数据呢,只是个人意见,本人实力很low,不对的还望指正

Repository owner deleted a comment from Haibarapink Jul 31, 2023
Repository owner deleted a comment from Haibarapink Jul 31, 2023
@Amadeus-cyf
Copy link

要么读写都不加,要么加rw lock,只在写方法加锁无法保证线程安全。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants