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
Segfault in AGS on CPUs with TSX (Haswell and above) when ulocking not locked pthread mutex #195
Comments
Thank you for report. So far we just recommended to turn it off on Linux by setting
in acsetup,cfg. (or just removing "threaded" parameter). |
Actually this is not directly related to audio. I think it's a design mistake that the mutex wrapper calls unlock in destructor. Its only function is to provide platform-independent interface. If someone forgot to unlock it properly in time, the consequences may be dire anyway. For automatic unlocking we have MutexLock. |
On a side note, did you consider using standard C++11 threads instead, or you need to support some old compilers which don't have it? It can eliminate maintaining all those different threading libraries and also allow much cleaner locking / mutex logic where things get cleaned out properly when they go out of scope without the need to manually clean it (RAII). Example: http://en.cppreference.com/w/cpp/thread/lock_guard There are also boost threads which are close to C++11 threads and are available for older compilers. |
On Windows Visual Studio 2008 is used... Am 14.10.2014 um 22:26 schrieb shmerl:
|
Yeah, VisualStudio still lags behind with C++11 (let alone 2008, even 2013 doesn't fully support it). However it should work with boost threads fine. |
We can't use higher Studio at the moment for some reasons, but we are moving towards that. Anyway, the auto locking is not a problem, because we have our own "lock guard", called MutexLock. The problem is the way audio objects are used, generally. But that is beyond scope of current issue. |
For the reference, my acsetup.cfg for the Quest for Infamy doesn't even have the [sound] section and no threaded parameter either, but this bug still appeared. |
True, I did not realize the true problem when making my very first comment. The solution is to remove Unlock call from destructor. |
I made a commit: a1f351b |
I tested it with the Quest for Infamy and it worked fine. Thanks for the fix! |
This comment was marked as abuse.
This comment was marked as abuse.
That's rather straightforward - using standard library which should work on any system with proper compilers. Otherwise you need to resort to lower level system dependent threads like now. C++11 isn't bleeding edge anymore. C++14 probably is. Most mature compilers including gcc and clang support it fully. What's lagging behind is VisualStudio. By the way, are there other compilers for Windows which can build ags but support C++11 at the same time? May be MinGW?
It offers cleaner logic of using locks and mutexes with RAII instead of explicit locking and unlocking like pthread API for example. So rewriting the code to use that approach will make it cleaner and less prone to errors. |
MinGW, perhaps.
We already have a RAII locking in AGS... as I told two time above :) We were considering moving to C++11 in some future, hypothetically, but we will definitely need to think this over more before doing so. |
Yes, but that unlock in this bug wasn't really in line with it :) I mean that it offers RAII in a standard fashion, so one doesn't need to reinvent the wheel. About MinGW - yes, that sounds like a good candidate. It will also untie developers who use AGS from proprietary tools. C++11 is pretty good at this time and used in different products in production already so if you worry about it being experimental - it's already not. |
Backtrace of the segfault:
I encountered this bug when trying to run the Quest for Infamy on current Debian testing (see the initial report).
The actual problem is triggered by invalidly unlocking the mutex which isn't locked. It's present in new glibc and on CPUs with TSX instructions (such as Haswell for example).
See this problem described here: https://bugzilla.novell.com/show_bug.cgi?id=853311
To fix it, unlocking should not happen if the mutex isn't locked. The workaround in the forum thread is just a dirty fix for the Quest for Infamy, but the engine should handle this more correctly.
The text was updated successfully, but these errors were encountered: