473,387 Members | 1,512 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,387 software developers and data experts.

Consecutive threads

As shown below, the genetic algorithm is applied to consecutive objects
The next calculation should not begin until the previous calculation ends

However, without any code between ...., calculation thread is generated simulataneously
As I monitor ts(ThreadState), it maintains constantly 'Background, Unstarted' even in the end of the calculation
If I insert while loop the thread does not start

If I use Thread.IsAlive, it works good. It shows 'false' when the calculation is terminated
But, I have no idea to apply this property to my code without while loop

How can I do that? Is an event in need
foreach (object o in objects

Calculate calc = new Calculate(o)

Thread t = calc.
ThreadState ts = t.ThreadStat
...
calc.Start()
...
class Calculatio

public Thread T {get {return t;}

public void Start(

t = new Thread(new ThreadStart(Evolution))
t.IsBackground = true
t.Start()
// Genetic algorith
private void Evolution(

.............

}
Nov 16 '05 #1
3 1724
I think you can create a sync object to lock from one thread.
What you do is create an object and then when a thread starts it locks the
object and releases the lock it when it ends.
Then the other thread has to wait until the object is not locked.
I could be way off base here because I have not done much threading.
Have a look at locks and threading in google and MSDN.

HTH
JB

What is the question?
That is the question.

"choyk1" <ch****@bmdrc.org> wrote in message
news:4E**********************************@microsof t.com...
As shown below, the genetic algorithm is applied to consecutive objects.
The next calculation should not begin until the previous calculation ends.

However, without any code between ...., calculation thread is generated simulataneously. As I monitor ts(ThreadState), it maintains constantly 'Background, Unstarted' even in the end of the calculation. If I insert while loop the thread does not start.

If I use Thread.IsAlive, it works good. It shows 'false' when the calculation is terminated. But, I have no idea to apply this property to my code without while loop.

How can I do that? Is an event in need?

foreach (object o in objects)
{
Calculate calc = new Calculate(o);

Thread t = calc.T
ThreadState ts = t.ThreadState
....
calc.Start();
....
}

class Calculation
{
public Thread T {get {return t;}}

public void Start()
{
t = new Thread(new ThreadStart(Evolution));
t.IsBackground = true;
t.Start();
}

// Genetic algorithm
private void Evolution()
{
..............
}
}

Nov 16 '05 #2
choyk1 <ch****@bmdrc.org> wrote:
As shown below, the genetic algorithm is applied to consecutive objects.
The next calculation should not begin until the previous calculation ends.


In that case, I suggest you don't use multiple threads in the first
place. Performing several consecutive calculations is exactly what a
single thread does best.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Choyk1,
I see you dont need parallelism in your application. Is there a
reasnon why you would use threads?
choyk1 wrote:
As shown below, the genetic algorithm is applied to consecutive objects.
The next calculation should not begin until the previous calculation ends.

However, without any code between ...., calculation thread is generated simulataneously.
As I monitor ts(ThreadState), it maintains constantly 'Background, Unstarted' even in the end of the calculation.
If I insert while loop the thread does not start.

If I use Thread.IsAlive, it works good. It shows 'false' when the calculation is terminated.
But, I have no idea to apply this property to my code without while loop.

How can I do that? Is an event in need?

foreach (object o in objects)
{
Calculate calc = new Calculate(o);

Thread t = calc.T
ThreadState ts = t.ThreadState
....
calc.Start();
....
}

class Calculation
{
public Thread T {get {return t;}}

public void Start()
{
t = new Thread(new ThreadStart(Evolution));
t.IsBackground = true;
t.Start();
}

// Genetic algorithm
private void Evolution()
{
..............
}
}


--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Adam | last post by:
Hi, I am trying to mark consective numbers in a data set and get a count as to how many consecutive numbers exist in the a given line of data. Here is an example line: 3, 5, 7, 9, 10, 13,...
3
by: choyk1 | last post by:
As shown below, the genetic algorithm is applied to consecutive objects The next calculation should not begin until the previous calculation ends However, without any code between ....,...
2
by: Beliavsky | last post by:
How can I replace multiple consecutive spaces in a file with a single character (usually a space, but maybe a comma if converting to a CSV file)? Ideally, the Python program would not compress...
7
by: Sharkie | last post by:
I need a regular expression which will evaluate to false if number of consecutive characters (non-whitespace) exceeds certain number (10 in this example). For example, I have this function: ...
6
by: cesco | last post by:
Hi, say I have a vector like the following: vec = and I'd like to know via a function (for example, ConsecutiveIntegers(vec, N)) whether there are N consecutive integers. So, for example,...
1
by: Mike | last post by:
Hi All, I'm using vb.net as my codebehind lang. and the following code is being executed in my aspx.vb page to stamp a DB row. Dim oStatsInfo As New StatsInfo(CartID, Batch, Set, Num, 0, 0, 0,...
16
by: sloan | last post by:
Current Framework 2.0/3.0. ... In Sql Server, there is a way to generate consecutive guid's. newsequentialid. Is there a way to reproduce this type of consecutive guid's in the framework.
8
by: gigonomics | last post by:
Hi all, I hope someone can help me out. I need to return the best available seats subject to the constraint that the seats are side by side (or return X consecutive records from a table column...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.