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

线程安全吗? #4

Open
sc4599 opened this issue Oct 5, 2020 · 1 comment
Open

线程安全吗? #4

sc4599 opened this issue Oct 5, 2020 · 1 comment

Comments

@sc4599
Copy link

sc4599 commented Oct 5, 2020

deercoder-chat/api/controllers/chat/chatWs 中的第20行 clinets 使用 []clent
这样做是否线程安全? 是否使用sync.Map 会更好一些

@dreamlu
Copy link
Owner

dreamlu commented Oct 26, 2020

安全, 因为没有并发写的情况
本质上是用的就是数组来模拟记录所有连接client, 各自启动一个新的线程来独立监听, 根据id标记客户端,没有线程交叉写的情况

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

2 participants