开发者

Multithreaded SDL error in C++

开发者 https://www.devze.com 2022-12-30 12:55 出处:网络
I\'m building a program in C++, using SDL, and am occasionally receiving this error: * glibc detected * ./assistant: double free or corruption (!prev)

I'm building a program in C++, using SDL, and am occasionally receiving this error:

* glibc detected * ./assistant: double free or corruption (!prev)

It's difficult to replicate, so I can't find exactly what's causing it, but I just added a second thread to the program, and neither thread run on its own seems to cause the error.

The threads don't share any开发者_JAVA百科 variables, though they both run the functions SDL_BlitSurface and SDL_Flip. Could running these concurrently throw up such an error, or am I barking up the wrong tree?

If this is the cause, should I simply throw a mutex around all SDL calls?


are you running with the MALLOC_CHECK_ environment variable set? This turns on memory checks in glibc, and I've had problems with it before because of a race condition in the glibc memory checking code (http://sourceware.org/bugzilla/show_bug.cgi?id=10282) which made it put out messages like this spuriously. Try running under valgrind and see if that sees any issues.


Turns out that it was being caused by the threads not terminating correctly. Instead of terminating them from main, I allowed them to return when they saw that main had finished running (through a global 'running' variable), and the problem disappeared.

0

精彩评论

暂无评论...
验证码 换一张
取 消