-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The total number of tickets in the system should be guaranteed not to exceed Integer.MAX_VALUE. #22
Comments
|
Add a interface "safeAdd" in LotteryScheduler class: /**
* @B22A
* Detect and prevent integer overflow for plus of two integers
*
* @param left left value of integer
* @param right right value of integer
*
* @return a integer, sum of left and right value
*/
static final int safeAdd(int left, int right) /* @B22A */
throws ArithmeticException { /* @B22A */
if (right > 0 ? left > Integer.MAX_VALUE - right /* @B22A */
: left < Integer.MIN_VALUE - right) { /* @B22A */
/* throw new ArithmeticException("Integer overflow"); */
return Integer.MAX_VALUE; /* @B22A */
} /* @B22A */
return left + right; /* @B22A */
}
Then use safeAdd to perform add operation for calculation of tickets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run MyTester.LotterySchedulerVAR3, hit the error:
[ThreadState.getEffectivePriority] holder thread: main (#0) Size: 1
[LotteryQueue.pickNextThread] Thread: main (#0) Priority: 1
java.lang.IllegalArgumentException
at java.util.Random.nextInt(Random.java:236)
at nachos.threads.LotteryScheduler$LotteryQueue.pickNextThread(LotteryScheduler.java:92)
at nachos.threads.PriorityScheduler$PriorityQueue.nextThread(PriorityScheduler.java:196)
at nachos.threads.KThread.runNextThread(KThread.java:351)
at nachos.threads.KThread.sleep(KThread.java:264)
at nachos.threads.KThread.finish(KThread.java:211)
at nachos.threads.KThread.runThread(KThread.java:163)
at nachos.threads.KThread.access$000(KThread.java:30)
at nachos.threads.KThread$1.run(KThread.java:150)
at nachos.machine.TCB.threadroot(TCB.java:240)
at nachos.machine.TCB.access$100(TCB.java:25)
at nachos.machine.TCB$1.run(TCB.java:93)
at java.lang.Thread.run(Thread.java:738)
The text was updated successfully, but these errors were encountered: