Class Scheduler
java.lang.Object
org.mpi_sws.jmc.runtime.scheduling.Scheduler
The scheduler is responsible for managing the execution of threads.
The scheduler uses the strategy to decide which thread to Schedule. To do so, it instantiates a separate SchedulerThread that is blocked whenever other threads are running and unblocked only when it needs to pick the next thread to schedule.
To interact with the scheduler, invoke the yield() which will defer control
the scheduler thread.
-
Constructor Summary
ConstructorsConstructorDescriptionScheduler(SchedulingStrategy strategy, int schedulerTries, long schedulerTrySleepTimeNanos) Constructs a new Scheduler object. -
Method Summary
Modifier and TypeMethodDescriptionReturns the ID of the current task.voidinit(TaskManager taskManager, Long mainTaskId) Initializes the scheduler with the task manager and the main thread.voidinitIteration(int iteration, JmcModelCheckerReport report) Initializes the strategy for a new iteration.voidvoidresetIteration(int iteration) Resets the TaskManager and the scheduling strategy for a new iteration.protected <T extends SchedulingChoiceValue>
voidscheduleTask(SchedulingChoice<T> choice) Performs the scheduling choice (instance ofSchedulingChoice) indicated.protected voidsetCurrentTask(Long taskId) Sets the ID of the current task.voidshutdown()Shuts down the scheduler.voidstart()Starts the scheduler thread.voidupdateEvent(JmcRuntimeEvent event) Updates the event in the scheduling strategy.yield()Pauses the current task and yields the control to the scheduler.Pauses the task with the given ID and yields the control to the scheduler.
-
Constructor Details
-
Scheduler
Constructs a new Scheduler object.- Parameters:
strategy- the scheduling strategy
-
-
Method Details
-
start
public void start()Starts the scheduler thread. -
init
Initializes the scheduler with the task manager and the main thread.- Parameters:
taskManager- the task managermainTaskId- the ID of the main thread
-
initIteration
Initializes the strategy for a new iteration.- Parameters:
iteration- the number of the iteration- Throws:
HaltCheckerException
-
currentTask
Returns the ID of the current task.- Returns:
- the ID of the current task
-
setCurrentTask
Sets the ID of the current task.- Parameters:
taskId- the ID of the current task
-
scheduleTask
Performs the scheduling choice (instance ofSchedulingChoice) indicated. Either resuming the task, stopping the task or stopping all tasks.- Parameters:
choice- The scheduling choice to make.
-
updateEvent
Updates the event in the scheduling strategy.- Parameters:
event- the event to be updated- Throws:
HaltTaskException
-
yield
Pauses the current task and yields the control to the scheduler.The call is non-blocking and returns immediately.
- Returns:
- a future that completes when the task is resumed
- Throws:
TaskAlreadyPaused- if the current task is already paused
-
yield
Pauses the task with the given ID and yields the control to the scheduler.The call is non-blocking and returns immediately.
- Parameters:
taskId- the ID of the task to be paused- Returns:
- a future that completes when the task is resumed
- Throws:
TaskAlreadyPaused- if the task is already paused
-
resetIteration
public void resetIteration(int iteration) Resets the TaskManager and the scheduling strategy for a new iteration. -
recordTrace
public void recordTrace() -
shutdown
public void shutdown()Shuts down the scheduler.
-