Copyright © 2001 Qusay H. Mahmoud
15
Pitfalls of Threads
l
One pitfall of threads is data sharing
–
Examples: Alice and Bob are sharing a checkbook
–
int balance;
–
boolean withdraw(int amount);
–
if (balance - amount >= 0) {
–
balance = balance - amount;
–
return true;
–
}
–
return false;
–
}
–