在 2019/4/12 9:49, Andrew Ng 写道: > I have attached a minimal patch that fixes the deadlock issue. > > The principle change to avoid deadlock, is to not wait whilst holding > the "waiters count lock". Because of this change to the locking, there > is an additional case required in the "signal" and "broadcast" functions > which handles when the "waiters count" goes to zero. >
I am not sure whether it is the right solution, however you are right here: The wait functions wait for `sema_b` first then try locking `waiters_count_lock_`, while the signal/broadcast functions try locking `waiters_count_lock_` before waiting for `sema_b`; that seems to be why deadlocks happen. This wait cycle can be broken by removing the wait and release operations on `sema_b` from wait functions. It may be safer because it doesn't break any invariant of the original implementation, where `sema_b` is always accessed with `waiters_count_lock_` held. > I'm away on holiday (vacation), so will probably not have time to sort > out the other changes that were included in my original patch which are > probably still worth while, particularly the removal of the locking from > the "sema" functions. > > Cheers, > Andrew > -- Best regards, LH_Mouse _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
