rem: if ((*outputs)[audioslot_sizet]->finished() == true) ecamain->output_finished = true;
context: void *mthread_process_chains(void* params) {  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); // other threads can stop this one  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);  ECA_PROCESSOR* ecamain = static_cast<ECA_PROCESSOR*>(params);  ecadebug->control_flow("Submix-thread ready");  ecadebug->msg(1,"(eca-main) Submix-pid: " + kvu_numtostr(getpid()));  vector<CHAIN*>* chains = ecamain->chains;  vector<AUDIO_IO*>* outputs = ecamain->outputs;  SAMPLE_BUFFER* mixslot = &(ecamain->mixslot);  vector<bool> chain_locked (ecamain->output_count);  while(true) {    for(int n = 0; n != ecamain->chain_count;) {      pthread_mutex_lock(ecamain->chain_muts[n]);      chain_locked[n] = true;      while(ecamain->chain_ready_for_submix[n] == false) {	pthread_cond_signal(ecamain->chain_conds[n]);	pthread_cond_wait(ecamain->chain_conds[n], ecamain->chain_muts[n]);      }      (*chains)[n]->process();      ++n;    }    for(int audioslot_sizet = 0; audioslot_sizet < ecamain->output_count; audioslot_sizet++) {      mixslot->number_of_channels((*outputs)[audioslot_sizet]->channels());      int count = 0;      for(int n = 0; n != ecamain->chain_count; n++) {	// --	// if chain is already released, skip	// --	if (chain_locked[n] == false) continue; 		if ((*chains)[n]->output_id == 0) {	  // --	  // skip, if chain is not connected to any output or is	  // disabled	  // --	  ecamain->chain_ready_for_submix[n] = false;	  chain_locked[n] = false;	  pthread_cond_signal(ecamain->chain_conds[n]);	  pthread_mutex_unlock(ecamain->chain_muts[n]);	  continue;	}	if ((*chains)[n]->output_id == (*outputs)[audioslot_sizet]) {	  // --	  // output is connected to this chain	  // --	  if (ecamain->output_chain_count[audioslot_sizet] == 1) {	    // --	    // there's only one output connected to this chain,	    // so we don't need to mix anything	    // --	    (*outputs)[audioslot_sizet]->write_buffer(&(*chains)[n]->audioslot);	    if ((*outputs)[audioslot_sizet]->finished() == true) ecamain->output_finished = true;	  }	  else {	    ++count;	    if (count == 1) {	      // -- 	      // this is the first chain connected to this output	      // --	      mixslot->copy((*chains)[n]->audioslot);	      mixslot->divide_by(ecamain->output_chain_count[audioslot_sizet]);	    }	    else {	      mixslot->add_with_weight((*chains)[n]->audioslot, ecamain->output_chain_count[audioslot_sizet]);	      if (count == ecamain->output_chain_count[audioslot_sizet]) {		(*outputs)[audioslot_sizet]->write_buffer(mixslot);		if ((*outputs)[audioslot_sizet]->finished() == true) ecamain->output_finished = true;	      }	    }	  }	  ecamain->chain_ready_for_submix[n] = false;	  chain_locked[n] = false;	  pthread_cond_signal(ecamain->chain_conds[n]);	  pthread_mutex_unlock(ecamain->chain_muts[n]);	}      }    }    ecamain->trigger_outputs();    pthread_testcancel();  }  cerr << "(eca-main/submix) You should never see this message!\n";}