View Single Post
Old 10-28-2004, 07:53 AM   #10 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,735
redhead is on a distinguished road
The problem is in the thread handling in Java, if you withdraw befor you add then withdraw again, it is going to be different than add, withdraw, add.
It all depends on how the threads lock the program from any inteference from other threads performing actions uppon the total ammount.
Thats why you need to try different aproaches ie:
Quote:
part 1:

Use Java Synchronization to avoid the race condition presented in the code.

part 2:

Use semaphore approach for this problem.

part 3:

Modify the code so that only one payroll thread and one withdraw thread are launched.
Then use Peterson's solution for mutual exclusion between the payroll and withdraw threads
What Bel is trying to tell you is this, figure it out by looking at how Java handles threads in teh ways you need to test it. (part 1, 2, 3)
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote