G'Day,
I have a re-occurring problem and wish to design a framework or
pattern to address it. I have some Ideas but I would like to do some
brainstorming with my peers before commencing.
The problem:
Several computational tasks I am running for my PhD work require
several weeks to complete and I will to be able to pause these tasks
and close the application periodically. It can be difficult to run a
machine several weeks without the windows operating system fowling up
at some point and requiring a restart... also it would need to be
paused so I can play crysis :) .
Any way these computations generally run in a while loop inside of one
of many (4) threads concurrently working on the problem..
mythread() { while(!finished) { getDataToworkOn(); doWork();
postResults();} }
sometimes the algorithm is in the pooling form..
while(!solutionfound) { ThreadPool.QueueUserWorkItem(testdati[++i]) }
I am looking to create something like a SuspendableTask class... One
of the requirements is that the "SuspendableTask" can be running many
other child "SuspendableTasks" and when the parent task is suspended
all children must also be suspended.
Here is my thought on a solution (not actual code just a quick psuedo
code and lefty out thread safety stuff), pease post your own
thoughts...
class SuspendableTask : ISuspendableTask
{
public static List<string, ISuspendableTaskmasterTaskList;
bool taskPaused=false;
ITaskData data;
public volatile int workload=0;
public SuspendableTask(string name, ITaskData d)
{
data=d;
masterTaskList.add(name, this);
}
public static void pause(string name) {masterTaskList[name].paused =
true;}
public bool continue() {return !(paused || data.solved())};
}
then each thread could look something like
mythread() {
while(SuspendableTask.masterTaskList["trainNN"].continue())
{...do work ...}
}
Well to me I think there is a more elegant solution out there.... and
I'm sure someones already using it.
thanks for any sugestions,
-dm