• unknown's avatar
    Avoiding a theoretically possible crash (pthread_mutex_lock(0)) which could... · d475643d
    unknown authored
    Avoiding a theoretically possible crash (pthread_mutex_lock(0)) which could (at least in POSIX Threads books)
    happen on SMP machines, when a thread is going to wait on a condition and it is KILLed at the
    same time.
    Cleaning code a bit by adding a test in enter_cond() that we have the mutex (was already the case in all places
    where it's called except one which is fixed here).
    
    
    sql/log.cc:
      safe_mutex_assert_owner() is now in THD::enter_cond()
    sql/slave.cc:
      lock mutex before waiting on condition.
    sql/sql_class.cc:
      THD::awake(): before locking the mutex, let's test it's not zero;
      in theory indeed, the killer thread may see current_cond non-zero and current_mutex zero
      (order of assignments is not guaranteed by POSIX).
      A comment noting that there is still a small chance a KILL does not work and needs
      being re-issued.
    sql/sql_class.h:
      Assert in enter_cond() that we have the mutex.
      It is already the case in all places where we call enter_cond(), so better ensure it there.
    d475643d
slave.cc 112 KB