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
"Critical section already initialized" on startup #874
Comments
Initializing a critical section that's already been initialized is explicitly called out as undefined behavior in the Windows documentation, so this should be fixed ASAP. I'll look deeper into it. |
From what I can tell the issue is that all threads and mutices share the same critical section, but call Fixing it may require refactoring. |
Causes undefined behavior in issue #874.
I don't think it's actually that pervasive, but there was indeed a double initialization that happened at startup in the logging system, fixed via da4b716. Could you try your analysis again with that commit applied? |
Okay, I see now, mutices don't actually share a critical section, the critical section object is malloc'd which I missed due to weirdness filter (it's unusual in Win32 to have a concrete object, almost everything is a system-provided handle). So my initial diagnosis was indeed wrong. I'll check it out with da4b716 applied and let you know if the issue is fixed. |
@SiegeLord Your patch fixes the double initialization, but doesn't fix the second error.
Which occurs here: Line 310 in da4b716
|
Do you have more of a stack trace for that? |
Looks like it happens in the audio stream thread:
|
I looked into this a bit, and managed to reproduce this with a very basic usage of the condition variable: #include <allegro5/allegro.h>
typedef struct STUFF
{
bool var;
ALLEGRO_MUTEX* mutex;
ALLEGRO_COND* cond;
} STUFF;
static void *proc(ALLEGRO_THREAD *thread, void *arg)
{
STUFF* stuff = (STUFF*)arg;
al_lock_mutex(stuff->mutex);
stuff->var = true;
al_signal_cond(stuff->cond);
al_unlock_mutex(stuff->mutex);
while (!al_get_thread_should_stop(thread))
{
al_rest(0.1);
}
return thread;
}
int main(int argc, const char *argv[])
{
al_init();
STUFF stuff;
stuff.cond = al_create_cond();
stuff.mutex = al_create_mutex();
stuff.var = false;
ALLEGRO_THREAD* thread = al_create_thread(proc, &stuff);
al_start_thread(thread);
al_lock_mutex(stuff.mutex);
while (!stuff.var) {
al_wait_cond(stuff.cond, stuff.mutex);
}
al_unlock_mutex(stuff.mutex);
al_join_thread(thread, NULL);
al_destroy_cond(stuff.cond);
al_destroy_mutex(stuff.mutex);
return 0;
} It sounds like Allegro's windows condition variables are not implemented in a way that's verifier likes. |
The verifier seems to expect a different thread to own the critical section than the one that actually does, which is baffling. |
Running miniSphere under Application Verifier in Windows with all options under "Basics" checked, AppVerifier triggers a breakpoint on the line below and prints the following text to the console:
allegro5/src/win/wxthread.c
Line 105 in 4f465a9
If I ignore the error and continue, I get another AppVerifier breakpoint here:
allegro5/src/win/wxthread.c
Line 310 in 4f465a9
AppVerifier doesn't allow me to continue past that point so I can't see if anything else is wrong.
The text was updated successfully, but these errors were encountered: