From 0d6cc4009345d4eb5327c4755f45989fbfb007a4 Mon Sep 17 00:00:00 2001 From: Colden Cullen Date: Thu, 24 Apr 2014 17:42:01 -0400 Subject: [PATCH] Parallelized task execution, fixed bug when removing multiple tasks. Closes #162. --- source/utility/tasks.d | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/utility/tasks.d b/source/utility/tasks.d index 4f0c0a0a..522f5481 100644 --- a/source/utility/tasks.d +++ b/source/utility/tasks.d @@ -3,13 +3,14 @@ * */ module utility.tasks; -import utility.time; +import utility.time, utility.output; import gl3n.util: is_vector, is_matrix, is_quaternion; import gl3n.interpolate: lerp; import core.time; import std.algorithm: min; +import std.parallelism: parallel; public: /** @@ -258,12 +259,12 @@ void scheduleDelayedTask( void delegate() dg, Duration delay ) void executeTasks() { size_t[] toRemove; // Indicies of tasks which are done - foreach( i, task; scheduledTasks ) + foreach( i, task; parallel( scheduledTasks ) ) { if( task() ) - toRemove ~= i; + synchronized toRemove ~= i; } - foreach( i; toRemove ) + foreach_reverse( i; toRemove ) { // Get tasks after one being removed auto end = scheduledTasks[ i+1..$ ];