From 25cc35b0e4942e990c01ac6224720e8fe84fd9ae Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 4 Oct 2017 10:44:24 +0200 Subject: bug(#9): Fix interference between experiments This change fixes the interference of multiple experiments running at the same time due to some thread unsafe behaviour in the JpaExperimentManager class. The code has now been restructured to solve the issue and fix the thread unsafe behaviour. Closes #9. --- .../src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt') diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt index b1d881a1..761f14b1 100644 --- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt +++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt @@ -83,16 +83,14 @@ open class Machine : Entity, Process { var task: Task = receiveTask() update(State(Status.RUNNING, task, load = 1.0, memory = state.memory + 50, temperature = 30.0)) - task.run { start() } while (true) { - if (task.remaining <= 0) { - task.run { finalize() } + if (task.finished) { logger.info { "${entity.id}: Task ${task.id} finished. Machine idle at $time" } update(State(Status.IDLE)) task = receiveTask() } else { - task.run { consume(speed * delta) } + task.consume(time, speed * delta) } // Check if we have received a new order in the meantime. @@ -100,7 +98,6 @@ open class Machine : Entity, Process { if (msg is Task) { task = msg update(State(Status.RUNNING, task, load = 1.0, memory = state.memory + 50, temperature = 30.0)) - task.run { start() } } } } -- cgit v1.2.3