0
我想知道我怎麼能避免死鎖在這個程序避免死鎖 - 過程
void transfer(int from, into to, double amount) {
sem_t *sem_from, *sem_to;
sem_from=get_sem(from); //function that obtains the semaphore from bank account argument
sem_to=get_sem(to);
sem_wait(sem_from);
sem_wait(sem_to);
withdraw(from, amount);
deposit(to, amount);
sem_post(sem_to);
sem_post(sem_from);
}
感謝。
http://stackoverflow.com/questions/14423418/deadlock-transfer-program – cnicutar
總是測試系統調用的返回值。 –