Closed etosch closed 9 years ago
To do this correctly would need a better than round-robin scheduling.
(new Date()).getTime()
-- which is how javascript returns the current time in millisecondsTIME_SLICE = 20
or some appropriate value of milliseconds; actual value needs to be determined by experimentOur new scheduling algorithm would become:
execute the first thread... doNextInstruction()
until TIME_SLICE
milliseconds have passed.
Then pop that thread from the front of the "queue" and push it to the back.
This would still be a round-robin scheduler.
For bonus points, we could detect when a monitor-enter fails, and skip to the next thread. It should work even if we don't.
Can't we still do it as an array? The way I see it, you just need to sample the time as soon as you enter a thread and then keep doing doNextInstruction till the time slice expires. A while loop around the doNextInstruction should suffice I think. At monitor entry failure, we should just sacrifice the time slice and move on to the next thread.
ThreadTest currently only tests a single sub thread, from class ThreadB. Class ThreadA sleeps for a time. The code in TestThread needs to be uncommented, recompiled, and redexed to test sleeping.
For now, the argument to sleep corresponds to the number of clock ticks to sleep. Thread functions are handled here. Note that this file will be changing a lot, rapidly, so we need fairly fast turnaround time on this.