473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1685
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Danny Anderson | last post by:
Hola! I am working on a program where I am including a library that came with my numerical methods textbook. The "util.h" simply includes a large number of files. I had to change the util.h...
31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
5
by: Brian.Steele | last post by:
Greetings everyone. See http://www.spiceisle.com/cgi-bin/slideshow/slideshow.cgi?dir=brian/personal/2005/uk_trip/images&type=jpg The "Pause" button works in IE, but not in Firefox. Any ideas...
11
by: Paminu | last post by:
Is there something like system("PAUSE") for linux?
4
by: Kerwin Cabrera | last post by:
I am writing a console application and I would like to put a "Press any key..." message once the program is done executing. Currently, when it executes it returns to the prompt. I have tried...
1
by: lucas | last post by:
Hi, is there a way to terminate a user session? I created a web service that loops trough a database that contains emails and sends a personnaly adressed email to everyone. The web service is...
3
by: RR | last post by:
I have a button on a form (form A) that opens another form. The form that opens (form B) has a listbox that is populated with a call to a function in the "on current" event. When form B with the...
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
5
by: CoderMarc | last post by:
Hi, I can not get the system pause to work in a simple program. Here is my program below: // i/o example #include <iostream> using namespace std; int main ()
2
by: Charles Zhang | last post by:
For Win32 application, I could use "__asm pause". However, for X64 platform, the inline assembler is not supported. Is there a compiler intrinsics for "__asm pause"? Thanks Charles Zhang
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.