_addThreat crash

I guess anyone who has ever launched TC is familiar with the infamous _addThreat crash (http://pastebin.com/afQLE7iH)

I have spent lots of time researching it and trying to fix it, but no luck. I have noticed that adding any kind of mutex to _addThreat causes map update threads to freeze.

Few things I tried:

-ACE_GUARD, it causes function to return instantly if mutex is locked already instead of blocking the thread until mutex gets released (as normal mutex would) = freeze

-ACE_GUARD_RETURN on both _addThreat and getThreat, same as ACE_GUARD, just allows to specify return value. = freeze

-Non-recursive POSIX mutex (http://pastebin.com/ZufP28eC), blocks thread while mutex is locked and continues execution later on. = freeze

Then I researched deeper and found that _addThreat can call addThreat witch would call _addThreat again so causing deadlock because non-recursive mutex can’t be locked multiple times.

-Recursive POSIX mutex (http://pastebin.com/JqWczgau), same as non-recursive mutex, but can be locked multiple times by same thread- allows mutexing recursive functions. = freeze

P.S POSIX mutexes are for UNIX only

And I don’t understand this anymore. If it freezes with recursive mutex then it suggests infinite loop in _addThreat itself (doesn’t unlock mutex), but that doesn’t explain why it crashes without mutex and freezes with one.

What have you tried to prevent it and what you think about this crash?

I tried a lot of stuffs too, nothing worked.

Finally, at the cost of having a functionality not working, I have removed the

else ref->getSource()->addThreat(pVictim, threat / size); completly, with high players count it was too often.

[/CODE]

You should first find out if the crash you described is caused by concurrent access or not. If not, you may throw the entire mutex idea out of the window.

Also, if you are going to use mutexes, you should use ACE library since it is cross-platform thanks to its #defines.

What we can wait removing this lines ?

And…

Yes, same here, impossible fix this crash, maybe a complete rewrite on threat system =/

Try http://www.trinitycore.org/f/topic/234-threat/page__view__findpost__p__21574

Thanks for de Reply but i think that changes dont affect the crash…

Its a major and old crash ( very very old )

And yet it seems to appear in very selective scenarios.

I for one never had it.

You probably run Mapupdate.threads = 1.

Yes with thread > 1, this crash is very constant…

Removing


else

            ref->getSource()->addThreat(pVictim, threat / size);

Fix the problem lol /emoticons/default_tongue.png

If I recall correctly, healers threat will be affected

A patch which does not allow _addThreat being called if the creature is in another map:

https://github.com/TrinityCore/TrinityCore/commit/8aead2a1eea446c3a8ca40ac7c3c9ad13bc88ef9

Do not know if that fix the problem. But threatmanager is still thread unsafe.