Para o problema da destruição das threads, nós verificamos na hora do join se a thread está ativa, ou seja, se o estado é READY ou SUSPENDED:
// Check if the thread is 'active'
if (_state == READY || _state == SUSPENDED) {
_waiting.insert(&_running->_link);
_running->suspend();
}
Para a verificação acima funcionar, tivemos que forçar o estado da thread para FINISHING no destrutor:
~Thread() {
_ready.remove(this);
_suspended.remove(this);
_state = FINISHING;
free(_stack);
}
No teste da implementação deletamos o phil[1] antes do for no método main, e a saída foi:
Philosopher 0 ate 10 times Philosopher 1 ate 0 times Philosopher 2 ate 10 times Philosopher 3 ate 10 times Philosopher 4 ate 10 times The end!