Consecutive threads

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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(

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

}
 
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 said:
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.
 
choyk1 said:
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.
 
Choyk1,
I see you dont need parallelism in your application. Is there a
reasnon why you would use threads?
 
Back
Top