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

pthread_mutex_lock and MutexAttempt causing Deadlock #182

Closed
3246251196 opened this issue Jun 2, 2024 · 1 comment
Closed

pthread_mutex_lock and MutexAttempt causing Deadlock #182

3246251196 opened this issue Jun 2, 2024 · 1 comment

Comments

@3246251196
Copy link
Member

3246251196 commented Jun 2, 2024

PTHREAD_MUTEX_ERRORCHECK.zip
The code above are snippets from Mednafen.

While porting Mednafen I noticed that I was getting a deadlock situation. I think the following:

    if (mutex->kind == PTHREAD_MUTEX_ERRORCHECK) {
        SHOWMSG("MutexAttempt");
        BOOL isLocked = MutexAttempt(mutex->mutex);
        if (!isLocked) {
            SHOWMSG("DeadLock");
            return EDEADLK;
        }
    }

MutexAttempt (ExecSG):

*   NAME
* 	MutexAttempt -- Try to lock a mutex                              (V52)
*
*   SYNOPSIS
*	BOOL MutexAttempt(APTR mx);
*
*   FUNCTION
*	This function attempts to lock the mutex mx. This function will never

It looks like we are locking the mutex, checking that it was not locked and then, because of that, trying to lock it again. Although, I can see the idea for MutexAttempt is to see whether or not we can get the mutex and if it already is locked the idea would be to check !isLocked and return EDEADLK - but that is not happening in the test case. But if it does lock then we need to handle that and not try to lock it again.

@3246251196
Copy link
Member Author

Resolved.

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

1 participant