n64dev / cen64

Cycle-Accurate Nintendo 64 Emulator
BSD 3-Clause "New" or "Revised" License
803 stars 70 forks source link

Possible deadlock issues #224

Open ryancaicse opened 2 years ago

ryancaicse commented 2 years ago

Hi, it seems that lock device->sync_mutex is missed to be released after 248. In the while loop, the lock could be acquired twice and a deadlock occurs. https://github.com/n64dev/cen64/blob/1b31ca9b3c3bb783391ab9773bd26c50db2056a8/device/device.c#L230-L256

ryancaicse commented 2 years ago

Here is another one similar to the above. https://github.com/n64dev/cen64/blob/1b31ca9b3c3bb783391ab9773bd26c50db2056a8/device/device.c#L230-L255

ryancaicse commented 2 years ago

Could anyone take a look? thanks

tj90241 commented 1 year ago

This is expected... see the manpage for pthread_cond_wait:

These functions atomically release mutex and cause the calling thread to block on the condition variable cond; atomically here means "atomically with respect to access by another thread to the mutex and then the condition variable".