469,592 Members | 1,893 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

A brainstorming session on "pause-able" for & while loops.

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

Nov 15 '07 #1
1 1513
It sounds like you've got the wrong algorithm entierly, to be honest.

You high-level description just screams "MSMQ", "Persistant Storage",
"Guaranteed Delivery", "Transactions". You'll probably want a Queue of Work
To Do, and a Queue of Results.

Your loop would, inside a Transaction:
0 - Create a Transaction
1 - Pull the work item out of the Work Queue
2 - Process it
3 - put the data into the Result queue
4 - Commit the Transaction

On some periodic schedule (one a day, once a week, etc) you would pull out
the Results and write them to long term storage (a database / file / etc).
At the same time you would populate the Work To Do queue with items that
need processing.

This is loosley coupled approach, with persistance and transactions, is
really going to be the only type of answer you can go with given your
descriptions. Anything else runs the risk of missing work items, or having
issues if the machine crashes, your process runs out of memory, or something
else unexpected happens.

--
Chris Mullins

"Wazza" <th*********@gmail.comwrote in message
news:11*********************@e34g2000pro.googlegro ups.com...
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

Nov 15 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Danny Anderson | last post: by
31 posts views Thread by da Vinci | last post: by
11 posts views Thread by Paminu | last post: by
4 posts views Thread by Kerwin Cabrera | last post: by
1 post views Thread by lucas | last post: by
3 posts views Thread by RR | last post: by
34 posts views Thread by Frederick Gotham | last post: by
2 posts views Thread by Charles Zhang | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.