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

想请教下这两种情况 #45

Open
shadowbanewuha opened this issue Jul 22, 2024 · 2 comments
Open

想请教下这两种情况 #45

shadowbanewuha opened this issue Jul 22, 2024 · 2 comments

Comments

@shadowbanewuha
Copy link

想请教下这两种情况:
情况A: 怪物搜寻附近玩家并主动发起攻击;
情况B: 怪物被玩家攻击后对玩家进行反击。
这两种情况是如何保证在一个线程里完成的呢。
虽然使用mutex很容易实现,但是这种情况下大量进行加锁/解锁,会严重影响程序效率吧。

我看到你的程序中会先从 m_offenderList 里面读取玩家UID,如果没有读取到则从 m_inViewCOList 计算出最近的玩家UID。
我没有搞明白这是如何保证它们在一个线程里面安全执行的

@etorth
Copy link
Owner

etorth commented Jul 22, 2024

All on_AM_XXXX() functions are called sequentially.
Actually this is done by the actor model, you can search this term for better understanding.
with this model we don't need to add lock for multi-threads program.

@shadowbanewuha
Copy link
Author

明白咯,多谢大佬!

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